Plotter Module

class plotter.TaylorDiagram(refstd, radmax=1.5, fig=None, rect=111, label='_')

Taylor diagram helper class

Plot model standard deviation and correlation to reference (data) sample in a single-quadrant polar plot, with r=stddev and theta=arccos(correlation).

This class was released as public domain by the original author Yannick Copin. You can find the original Gist where it was released at: https://gist.github.com/ycopin/3342888

Set up Taylor diagram axes, i.e. single quadrant polar plot, using mpl_toolkits.axisartist.floating_axes. refstd is the reference standard deviation to be compared to.

add_contours(std1, corr1, std2, corr2, **kwargs)

Add a line between two points [std1, corr1] and [std2, corr2]

add_rms_contours(levels=5, **kwargs)

Add constant centered RMS difference contours.

add_sample(stddev, corrcoef, *args, **kwargs)

Add sample (stddev,corrcoeff) to the Taylor diagram. args and kwargs are directly propagated to the Figure.plot command.

add_stddev_contours(std, corr1, corr2, **kwargs)

Add a curved line with a radius of std between two points [std, corr1] and [std, corr2]

plotter.draw_barchart(results, yvalues, fname, ptitle='', fmt='png', xlabel='', ylabel='')

Draw a barchart.

Parameters:
  • results (numpy.ndarray) – 1D array of data.
  • yvalues – List of y-axis labels
  • fname (string) – Filename of the plot.
  • ptitle (string) – (Optional) plot title.
  • fmt (string) – (Optional) filetype for the output.
  • xlabel (string) – (Optional) x-axis title.
  • ylabel (string) – (Optional) y-axis title.
plotter.draw_contour_map(dataset, lats, lons, fname, fmt='png', gridshape=(1, 1), clabel='', ptitle='', subtitles=None, cmap=None, clevs=None, nlevs=10, parallels=None, meridians=None, extend='neither', aspect=3.4)

Draw a multiple panel contour map plot.

Parameters:
  • dataset (numpy.ndarray) – 3D array of data to be plotted with shape (nT, nLat, nLon).
  • lats (numpy.ndarray) – Array of latitudes values.
  • lons (numpy.ndarray) – Array of longitudes
  • fname (string) – The filename of the plot.
  • fmt (string) – (Optional) filetype for the output.
  • gridshape (tuple() of the form (num_rows, num_cols)) – (Optional) tuple denoting the desired grid shape (num_rows, num_cols) for arranging the subplots.
  • clabel (string) – (Optional) colorbar title.
  • ptitle (string) – (Optional) plot title.
  • subtitles (list of string) – (Optional) list of titles for each subplot.
  • cmap (string or matplotlib.colors.LinearSegmentedColormap) – (Optional) string or matplotlib.colors.LinearSegmentedColormap instance denoting the colormap. This must be able to be recognized by Matplotlib’s get_cmap function.
  • clevs (list of int or float) – (Optional) contour levels values.
  • nlevs (int) – (Optional) target number of contour levels if clevs is None.
  • parallels (list of int or float) – (Optional) list of ints or floats for the parallels to be drawn. See the Basemap documentation for additional information.
  • meridians (list of int or float) –

    (Optional) list of ints or floats for the meridians to be drawn. See the Basemap documentation for additional information.

  • extend (string) – (Optional) flag to toggle whether to place arrows at the colorbar boundaries. Default is ‘neither’, but can also be ‘min’, ‘max’, or ‘both’. Will be automatically set to ‘both’ if clevs is None.
plotter.draw_histogram(dataset_array, data_names, fname, fmt='png', nbins=10)
Purpose::
Draw histograms
Input::
dataset_array - a list of data values [data1, data2, ....] data_names - a list of data names [‘name1’,’name2’,....] fname - a string specifying the filename of the plot bins - number of bins
plotter.draw_marker_on_map(lat, lon, fname, fmt='png', location_name=' ', gridshape=(1, 1))
Purpose::
Draw a marker on a map
Input::
lat - latitude for plotting a marker lon - longitude for plotting a marker fname - a string specifying the filename of the plot

Fill the States over the contiguous US with colors

Parameters:
  • obs_data (:class:'numpy.ndarray') – An array of observed trend and standard errors for regions
  • ens_data (: class:'numpy.ndarray') – An array of trend and standard errors from a multi-model ensemble for regions
  • model_data (: class:'numpy.ndarray') – An array of trends from models for regions
  • fname (string) – The filename of the plot.
  • fmt (string) – (Optional) filetype for the output.
  • ptitle (string) – (Optional) plot title.
  • data_labels (list) – (Optional) names of the regions
  • xlabel (string) – (Optional) a label for x-axis
  • ylabel (string) – (Optional) a label for y-axis
plotter.draw_portrait_diagram(results, rowlabels, collabels, fname, fmt='png', gridshape=(1, 1), xlabel='', ylabel='', clabel='', ptitle='', subtitles=None, cmap=None, clevs=None, nlevs=10, extend='neither', aspect=None)

Draw a portrait diagram plot.

Parameters:
  • results (numpy.ndarray) – 3D array of the fields to be plotted. The second dimension should correspond to the number of rows in the diagram and the third should correspond to the number of columns.
  • rowlabels (list of string) – Labels for each row.
  • collabels (list of string) – Labels for each row.
  • fname (string) – Filename of the plot.
  • fmt (string) – (Optional) filetype for the output.
  • gridshape (tuple() of the form (num_rows, num_cols)) – (Optional) tuple denoting the desired grid shape (num_rows, num_cols) for arranging the subplots.
  • xlabel (string) – (Optional) x-axis title.
  • ylabel (string) – (Optional) y-ayis title.
  • clabel (string) – (Optional) colorbar title.
  • ptitle (string) – (Optional) plot title.
  • subtitles (list of string) – (Optional) list of titles for each subplot.
  • cmap (string or matplotlib.colors.LinearSegmentedColormap) –

    (Optional) string or matplotlib.colors.LinearSegmentedColormap instance denoting the colormap. This must be able to be recognized by Matplotlib’s get_cmap function.

  • clevs (list of int or float) – (Optional) contour levels values.
  • nlevs (int) – Optional target number of contour levels if clevs is None.
  • extend (string) – (Optional) flag to toggle whether to place arrows at the colorbar boundaries. Default is ‘neither’, but can also be ‘min’, ‘max’, or ‘both’. Will be automatically set to ‘both’ if clevs is None.
  • aspect (float) – (Optional) approximate aspect ratio of each subplot (width / height). Default is 8.5 / 5.5
plotter.draw_precipitation_JPDF(plot_data, plot_level, x_ticks, x_names, y_ticks, y_names, output_file, title=None, diff_plot=False, cmap=<matplotlib.colors.LinearSegmentedColormap object>, cbar_ticks=[0.01, 0.1, 0.5, 2, 5, 25], cbar_label=['0.01', '0.10', '0.5', '2', '5', '25'])
Parameters:
  • plot_data (:class:'numpy.ndarray') – a numpy array of data to plot (dimY, dimX)
  • plot_level (:class:'numpy.ndarray') – levels to plot
  • x_ticks (:class:'numpy.ndarray') – x values where tick makrs are located
  • x_names (:class:'list') – labels for the ticks on x-axis (dimX)
  • y_ticks (:class:'numpy.ndarray') – y values where tick makrs are located
  • y_names (:class:'list') – labels for the ticks on y-axis (dimY)
  • output_file (:mod:'string') – name of output png file
  • title (:mod:'string') – (Optional) title of the plot
  • diff_plot (:mod:'bool') – (Optional) if true, a difference plot will be generated
  • cbar_ticks (:class:'list') – (Optional) tick marks for the color bar
  • cbar_label (:class:'list') – (Optional) lables for the tick marks of the color bar
plotter.draw_subregions(subregions, lats, lons, fname, fmt='png', ptitle='', parallels=None, meridians=None, subregion_masks=None)

Draw subregion domain(s) on a map.

Parameters:
  • subregions (list of subregion objects (Bounds objects)) – The subregion objects to plot on the map.
  • lats (numpy.ndarray) – Array of latitudes values.
  • lons (numpy.ndarray) – Array of longitudes values.
  • fname (string) – The filename of the plot.
  • fmt (string) – (Optional) filetype for the output.
  • ptitle (string) – (Optional) plot title.
  • parallels (list of int or float) –

    (Optional) list of int or float for the parallels to be drawn. See the Basemap documentation for additional information.

  • meridians (list of int or float) –

    (Optional) list of int or float for the meridians to be drawn. See the Basemap documentation for additional information.

  • subregion_masks (dict of bool arrays) – (Optional) dict of bool arrays for each subregion for giving finer control of the domain to be drawn, by default the entire domain is drawn.
plotter.draw_taylor_diagram(results, names, refname, fname, fmt='png', gridshape=(1, 1), ptitle='', subtitles=None, pos='upper right', frameon=True, radmax=1.5)

Draw a Taylor diagram.

Parameters:
  • results (numpy.ndarray) – An Nx2 array containing normalized standard deviations, correlation coefficients, and names of evaluation results.
  • names (list of string) – A list of names for each evaluated dataset
  • refname (string) – The name of the reference dataset.
  • fname (string) – The filename of the plot.
  • fmt (string) – (Optional) filetype for the output plot.
  • gridshape (A tuple of the form (num_rows, num_cols)) – (Optional) Tuple denoting the desired grid shape (num_rows, num_cols) for arranging the subplots.
  • ptitle (string) – (Optional) plot title.
  • subtitles (list of string) – (Optional) list of strings specifying the title for each subplot.
  • pos (string or tuple() of float) – (Optional) string or tuple of floats used to set the position of the legend. Check the Matplotlib docs for additional information.
  • frameon (bool) – (Optional) boolean specifying whether to draw a frame around the legend box.
  • radmax (float) – (Optional) float to adjust the extent of the axes in terms of standard deviation.
plotter.draw_time_series(results, times, labels, fname, fmt='png', gridshape=(1, 1), xlabel='', ylabel='', ptitle='', subtitles=None, label_month=False, yscale='linear', aspect=None)

Draw a time series plot.

Parameters:
  • results (numpy.ndarray) – 3D array of time series data.
  • times (list of datetime.datetime) – List of Python datetime objects used by Matplotlib to handle axis formatting.
  • labels (list of string) – List of names for each data being plotted.
  • fname (string) – Filename of the plot.
  • fmt (string) – (Optional) filetype for the output.
  • gridshape (tuple() of the form (num_rows, num_cols)) – (Optional) tuple denoting the desired grid shape (num_rows, num_cols) for arranging the subplots.
  • xlabel (string) – (Optional) x-axis title.
  • ylabel (string) – (Optional) y-axis title.
  • ptitle (string) – (Optional) plot title.
  • subtitles (list of string) – (Optional) list of titles for each subplot.
  • label_month (bool) – (Optional) flag to toggle drawing month labels on the x-axis.
  • yscale (string) – (Optional) y-axis scale value, ‘linear’ for linear and ‘log’ for log base 10.
  • aspect (float) – (Optional) approximate aspect ratio of each subplot (width / height). Default is 8.5 / 5.5
plotter.fill_US_states_with_color(regions, fname, fmt='png', ptitle='', colors=False, values=None, region_names=None)

Fill the States over the contiguous US with colors

Parameters:
  • regions (list) – The list of subregions(lists of US States) to be filled with different colors.
  • fname (string) – The filename of the plot.
  • fmt (string) – (Optional) filetype for the output.
  • ptitle (string) – (Optional) plot title.
  • colors (bool) – (Optional) : If True, each region will be filled with different colors without using values
  • values (numpy.ndarray) – (Optional) : If colors==False, color for each region scales an associated element in values
plotter.set_cmap(name)

Sets the default colormap (eg when setting cmap=None in a function) See: http://matplotlib.org/examples/pylab_examples/show_colormaps.html for a list of possible colormaps. Appending ‘_r’ to a matplotlib colormap name will give you a reversed version of it.

Parameters:name (string) – The name of the colormap.