plots.styles
Submodules
Attributes
Classes
A style for plotting data. |
Package Contents
- plots.styles.DEFAULT_STYLE
- class plots.styles.Style(colors=schema.default_cmap, levels=None, gradients=None, normalize=True, units=None, scale_factor=None, units_label=None, legend_style='colorbar', legend_kwargs=None, categories=None, ticks=None, preferred_method='contourf', resample=None, **kwargs)
A style for plotting data.
- Parameters:
colors (str or list or matplotlib.colors.Colormap, optional) – The colors to be used in this Style. This can be a named matplotlib colormap, a list of colors (as named CSS4 colors, hexadecimal colors or three (four)-element lists of RGB(A) values), or a pre-defined matplotlib colormap object. If not provided, the default colormap of the active schema will be used.
levels (list or earthkit.maps.styles.levels.Levels, optional) – The levels to use in this Style. This can be a list of specific levels, or an earthkit Levels object. If not provided, some suitable levels will be generated automatically (experimental!).
gradients (list, optional) – The number of colors to insert between each level in levels. If None, one color level will be inserted between each level.
normalize (bool, optional) – If True (default), then the colors will be normalized over the level range.
units (str, optional) – The units in which the levels are defined. If this Style is used with data not using the given units, then a conversion will be attempted; any data incompatible with these units will not be able to use this Style. If units are not provided, then data plotted using this Style will remain in their original units.
units_label (str, optional) – The label to use in titles and legends to represent the units of the data.
legend_style (str, optional) – The style of legend to use by default with this style. Must be one of colorbar (default), disjoint, histogram, or None (no legend).
bin_labels (list, optional) – A list of categorical labels for each bin in the legend.
- apply_scale_factor(values)
Apply the scale factor to some values.
- bar(ax, x, y, values, *args, mode='linear', **kwargs)
Plot a scatter plot using this Style.
- Parameters:
ax (matplotlib.axes.Axes) – The axes on which to plot the data.
x (numpy.ndarray) – The x coordinates of the data to be plotted.
y (numpy.ndarray) – The y coordinates of the data to be plotted.
values (numpy.ndarray) – The values of the data to be plotted.
**kwargs – Any additional arguments accepted by matplotlib.axes.Axes.scatter.
- barbs(ax, x, y, u, v, *args, **kwargs)
- colorbar(*args, **kwargs)
Create a colorbar legend for this Style.
- contour(ax, x, y, values, *args, **kwargs)
Plot line contours using this Style.
- Parameters:
ax (matplotlib.axes.Axes) – The axes on which to plot the data.
x (numpy.ndarray) – The x coordinates of the data to be plotted.
y (numpy.ndarray) – The y coordinates of the data to be plotted.
values (numpy.ndarray) – The values of the data to be plotted.
**kwargs – Any additional arguments accepted by matplotlib.axes.Axes.contour.
- contourf(ax, x, y, values, *args, **kwargs)
Plot shaded contours using this Style.
- Parameters:
ax (matplotlib.axes.Axes) – The axes on which to plot the data.
x (numpy.ndarray) – The x coordinates of the data to be plotted.
y (numpy.ndarray) – The y coordinates of the data to be plotted.
values (numpy.ndarray) – The values of the data to be plotted.
**kwargs – Any additional arguments accepted by matplotlib.axes.Axes.contourf.
- convert_units(values, source_units, short_name='')
Convert some values from their source units to this Style’s units.
- Parameters:
values (numpy.ndarray) – The values to convert from their source units to this Style’s units.
source_units (str) – The source units of the given values.
short_name (str, optional) – The short name of the variable, which is used to make extra assumptions about the data’s unit covnersion (for example, temperature anomalies need special consideration when converting between Celsius and Kelvin).
- disjoint(*args, **kwargs)
Create a disjoint legend for this Style.
- property extend
Convenience access to ‘extend’ kwarg.
- classmethod from_dict(kwargs)
Create a Style from a dictionary.
- gradients = None
- imshow(ax, x, y, values, *args, **kwargs)
Plot a pcolormesh using this Style.
- Parameters:
ax (matplotlib.axes.Axes) – The axes on which to plot the data.
x (numpy.ndarray) – The x coordinates of the data to be plotted.
y (numpy.ndarray) – The y coordinates of the data to be plotted.
values (numpy.ndarray) – The values of the data to be plotted.
**kwargs – Any additional arguments accepted by matplotlib.axes.Axes.pcolormesh.
- legend(*args, **kwargs)
Create the default legend for this Style.
- Parameters:
*args (list) – Arguments to be passed to the legend method.
**kwargs (dict) – Keyword arguments to be passed to the legend method.
- levels(data=None)
Generate levels specific to some data.
- Parameters:
data (numpy.ndarray or xarray.DataArray or earthkit.data.core.Base) – The data for which to generate a list of levels.
- Return type:
list
- line(ax, x, y, values, *args, mode='linear', **kwargs)
Plot a scatter plot using this Style.
- Parameters:
ax (matplotlib.axes.Axes) – The axes on which to plot the data.
x (numpy.ndarray) – The x coordinates of the data to be plotted.
y (numpy.ndarray) – The y coordinates of the data to be plotted.
values (numpy.ndarray) – The values of the data to be plotted.
**kwargs – Any additional arguments accepted by matplotlib.axes.Axes.scatter.
- normalize = True
- pcolormesh(ax, x, y, values, *args, **kwargs)
Plot a pcolormesh using this Style.
- Parameters:
ax (matplotlib.axes.Axes) – The axes on which to plot the data.
x (numpy.ndarray) – The x coordinates of the data to be plotted.
y (numpy.ndarray) – The y coordinates of the data to be plotted.
values (numpy.ndarray) – The values of the data to be plotted.
**kwargs – Any additional arguments accepted by matplotlib.axes.Axes.pcolormesh.
- plot(*args, **kwargs)
Plot the data using the Style’s defaults.
- quiver(ax, x, y, u, v, *args, **kwargs)
Plot quiver arrows using this Style.
- Parameters:
ax (matplotlib.axes.Axes) – The axes on which to plot the data.
x (numpy.ndarray) – The x coordinates of the data to be plotted.
y (numpy.ndarray) – The y coordinates of the data to be plotted.
u (numpy.ndarray) – The u-component of the data to be plotted.
v (numpy.ndarray) – The v-component of the data to be plotted.
**kwargs – Any additional arguments accepted by matplotlib.axes.Axes.quiver.
- resample = None
- save_legend_graphic(filename='legend.png', data=None, transparent=True, **kwargs)
Save a standalone image of the legend associated with this Style.
- Parameters:
filename (str) – The name of the image to save.
data (earthkit.data.core.Base, optional) – It can sometimes be useful to pass some data in order to automatically generate legend labels or color ranges, depending on the Style.
- scale_factor = None
- scatter(ax, x, y, values, s=3, *args, **kwargs)
Plot a scatter plot using this Style.
- Parameters:
ax (matplotlib.axes.Axes) – The axes on which to plot the data.
x (numpy.ndarray) – The x coordinates of the data to be plotted.
y (numpy.ndarray) – The y coordinates of the data to be plotted.
values (numpy.ndarray) – The values of the data to be plotted.
**kwargs – Any additional arguments accepted by matplotlib.axes.Axes.scatter.
- to_contour_kwargs(data)
Generate contour arguments required for plotting data in this Style.
- Parameters:
data (numpy.ndarray) – The data to be plotted using this Style.
- to_contourf_kwargs(data)
Generate contourf arguments required for plotting data in this Style.
- Parameters:
data (numpy.ndarray) – The data to be plotted using this Style.
- to_matplotlib_kwargs(data, extend_levels=True)
Generate matplotlib arguments required for plotting data in this Style.
- Parameters:
data (numpy.ndarray) – The data to be plotted using this Style.
- to_pcolormesh_kwargs(data)
Generate pcolormesh arguments required for plotting data in this Style.
- Parameters:
data (numpy.ndarray) – The data to be plotted using this Style.
- to_quiver_kwargs(data)
Generate quiver arguments required for plotting data in this Style.
- Parameters:
data (numpy.ndarray) – The data to be plotted using this Style.
- to_scatter_kwargs(data)
Generate scatter arguments required for plotting data in this Style.
- Parameters:
data (numpy.ndarray) – The data to be plotted using this Style.
- tricontourf(ax, x, y, values, *args, **kwargs)
Plot triangulated shaded contours using this Style.
- Parameters:
ax (matplotlib.axes.Axes) – The axes on which to plot the data.
x (numpy.ndarray) – The x coordinates of the data to be plotted.
y (numpy.ndarray) – The y coordinates of the data to be plotted.
values (numpy.ndarray) – The values of the data to be plotted.
**kwargs – Any additional arguments accepted by matplotlib.axes.Axes.tricontourf.
- tripcolor(ax, x, y, values, *args, **kwargs)
Plot triangulated shaded contours using this Style.
- Parameters:
ax (matplotlib.axes.Axes) – The axes on which to plot the data.
x (numpy.ndarray) – The x coordinates of the data to be plotted.
y (numpy.ndarray) – The y coordinates of the data to be plotted.
values (numpy.ndarray) – The values of the data to be plotted.
**kwargs – Any additional arguments accepted by matplotlib.axes.Axes.tricontourf.
- property units
Formatted units for use in figure text.
- values_to_colors(values, data=None)
Convert a value or list of values to colors based on this Style.
- Parameters:
values (float or list of floats) – The values to convert to colors on this Style’s color scale.
- vector(*args, **kwargs)
Create a vector legend for this Style.