maps.styles
Submodules
Package Contents
Classes
Class describing a mapping style. |
- class maps.styles.Style(colors=schema.cmap, levels=None, gradients=None, normalize=True, units=None, units_label=None, legend_style='colorbar', legend_kwargs=None, bin_labels=None, ticks=None, **kwargs)
Class describing a mapping style.
- 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. Note that passing units requires cf_units to be installed.
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.
- property extend
Convenience access to ‘extend’ kwarg.
- property units
Formatted units for use in figure text.
- barbs(ax, x, y, u, v, *args, **kwargs)
- colorbar(*args, **kwargs)
- 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 or cf_units.Unit) – 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)
- classmethod from_dict(kwargs)
- legend(*args, **kwargs)
Create the default legend for this Style.
- 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
- 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.
- 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.
- 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)
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_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.
- 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.