Plot
- class enstools.plot.Backend(value)
Enum class that defining a library for plotting.
- BOKEH = 2
- PLOTLY = 1
- class enstools.plot.Stream(value)
Enum class that defining a type of streamlines.
- LINE = 1
- VECTOR = 2
- enstools.plot.contour(variable, lon=None, lat=None, **kwargs)
Create a plot from an xarray variable that includes coordinates.
- Parameters
- variablexarray.DataArray
the data to plot.
- lonxarray.DataArray or np.ndarray or str
longitude coordinate or name of longitude coordinate. The name may only be used for xarray variables.
- latxarray.DataArray or np.ndarray or str
latitude coordinate or name of longitude coordinate. The name may only be used for xarray variables.
- Other optional keyword arguments:
- **kwargs
- figure: matplotlib.figure.Figure
If provided, this figure instance will be used (and returned), otherwise a new figure will be created.
- axes: matplotlib.axes.Axes
If provided, this axes instance will be used (e.g., of overplotting), otherwise a new axes object will be created.
- subplot_args: tuple
Arguments passed on to add_subplot. These arguments are used only if no axes is provided.
- subplot_kwargs: dict
Keyword arguments passed on to add_subplot. These arguments are used only if no axes is provided.
- filled: [True | False]
If True a filled contour is plotted, which is the default
- colorbar: [True | False | “empty”]
If True, a colorbar is created. Default=True. Use empty to reserve space for the colorbar without actually creating it. This is usefull for multipanel plots, where one panel has a colorbar and another not.
- levels: np.ndarray
If provided, these levels are used, otherwise the levels are automatically selected.
- levels_center_on_zerobool
If true, automatically selected levels are centered around zero.
- gridlines: [True | False]
If True, coordinate grid lines are drawn. Default=False
- gridline_labes: [True | False]
Whether or not to label the grid lines. The default is not to label them.
- coastlines: [True | False | ‘110m’ | ‘50m’ | ‘10m’]
If True, coordinate grid lines are drawn. Default=True
- coastlines_kwargs: dict
dictionary with arguments passed on to ax.coastlines()
- borders: [True | False | ‘110m’ | ‘50m’ | ‘10m’]
If True, coordinate grid lines are drawn. Default=False
- projection: [ cartopy.crs.Projection]
If not None, the Projection object is used to create the plot
- rotated_pole: [xarray.DataArray | dict]
Information about the rotated pole. This can either be the CF-standard rotated_pole variable from an input file, or alternatively a dictionary with the keys grid_north_pole_latitude and grid_north_pole_longitude.
- All other arguments are forwarded to the matplotlib contour or contourf function.
- Returns
- tuple
(Figure, Axes) of the new plot is returned. The returned values may be reused in subsequent calls to plot functions.
Examples
>>> fig, ax = enstools.plot.contour(data["TOT_PREC"][0, :, :], coastlines="50m")
24h ICON forecast for precipitation read from a grib2 file. Have a look at the script examples/example_plot_icon_01.py for more details.
>>> fig, ax1 = enstools.plot.contour(data["PMSL"][0, :] / 100.0, gridlines=True, subplot_args=(121,)) >>> fig, ax2 = enstools.plot.contour(data["TOT_PREC"][0, :], figure=fig, subplot_args=(122,))
24h ICON forecast for mean sea level pressure (left) and precipitation (right). The data was read from grib2 files on the native ICON grid and plotted without interpolation onto a regular grid. Have a look at the script examples/example_plot_icon_02.py
- enstools.plot.grid(plot_function, variable, lon=None, lat=None, figure=None, axes=None, shape=None, cmaps=None, **kwargs)
Create a multi-panel plot by mapping the first dimension of the input array to a plot function specified in the second argument.
- Parameters
- plot_functionCallable
the plot function to use. supported are all function in enstools.plot
- variablexarray.DataArray or np.ndarray
the data to plot. Should be an 3d-Array, the first dimension is used to create the grid.
- lonxarray.DataArray or np.ndarray or str
longitude coordinate or name of longitude coordinate. The name may only be used for xarray variables.
- latxarray.DataArray or np.ndarray or str
latitude coordinate or name of longitude coordinate. The name may only be used for xarray variables.
- figurematplotlib.figure.Figure
If provided, this figure instance will be used (and returned), otherwise a new figure will be created.
- axesarray of matplotlib.axes.Axes
if provided, this has to be an array of matplotlib.axes.Axes instances with the desired shape of the plot.
- shapetuple
The shape of the multi-panel plot (nrows, ncols). Not providing shape or axes is an error!
- cmapslist
A list of cmap names. The number of entries has to be the number of panel plots to create.
- **kwargs:
Keyword arguments, they are forwarded top the actual plt function that creates the individual panels
- Returns
- tuple:
fig, ax, where ax is an array for Axes objects
Examples
>>> fig, ax = grid(contour, data["TOT_PREC"][27, :, :, :], data["rlon"], data["rlat"], shape=(4, 5), cmaps=cmaps, rotated_pole=data["rotated_pole"], colorbar=False)
Example of displaying the result of K-Mean clustering for the COSMO-DE Ensemble. Each cluster has a different colormap.
- enstools.plot.interactive_contours(variable, lon=None, lat=None, **kwargs)
Creates a plot of interactive contours.
- Parameters
- variablexarray
Values of a variable and a range of other parameters describing the variable and the grid.
- lonxarray.DataArray or np.ndarray or str
longitude coordinate or name of longitude coordinate. The name may only be used for xarray variables.
- latxarray.DataArray or np.ndarray or str
latitude coordinate or name of longitude coordinate. The name may only be used for xarray variables.
- Other optional keyword arguments:
- **kwargs
- figure: bokeh or plotly figure object
If provided, this figure instance will be used (and returned), otherwise a new figure will be created.
- filled: [True | False]
If True a filled contour is plotted, which is the default
- selected_backendEnum element, optional, default=Library.BOKEH
Definition of a library for plotting. Element from Library Enum.
- aspectfloat, optional, default=None
Aspect ratio between a figure width and a height as a fraction.
- sizeint, optional, default=800
Size of a figure width in pixels. Size of a figure height is calculated from an aspectratio.
- map_resolution{‘110m’, ‘50m’, ‘10m’}, optional, default=’110m’
Definition of a map resolution.
- cmapstr
Name of the color map to use. Default: CMRmap_r
- line_widthint
Line width, default is 1.
- Returns
- figure
Figure object contains interactive contours with a colorbars.
- enstools.plot.interactive_streamlines(variable_u, variable_v, lon=None, lat=None, **kwargs)
Creates a plot of interactive streamlines or vectors.
- Parameters
- variable_u, variable_vxarray.DataArray
u- and v-component of streamline data.
- lonxarray.DataArray or np.ndarray or str
longitude coordinate or name of longitude coordinate. The name may only be used for xarray variables.
- latxarray.DataArray or np.ndarray or str
latitude coordinate or name of longitude coordinate. The name may only be used for xarray variables.
- Other optional keyword arguments:
- **kwargs
- figure: bokeh or plotly figure object
If provided, this figure instance will be used (and returned), otherwise a new figure will be created.
- selected_backendEnum element, optional, default=Library.BOKEH
Definition of a library for plotting. Element from Library Enum.
- aspectfloat, optional, default=None
Aspect ratio between a figure width and a height as a fraction.
- sizeint, optional, default=800
Size of a figure width in pixels. Size of a figure height is calculated from an aspectratio.
- map_resolution{‘110m’, ‘50m’, ‘10m’}, optional, default=’110m’
Definition of a map resolution.
- line_typeEnum element, optional, default=Stream.LINE
Definition of a line type. Element from Stream Enum.
- densityfloat, optional, default=2
Definition of a closeness of streamlines. When density = 1, the domain is divided into a 30x30 grid.
- scalefloat, optional, default=0.02
Possibility to scale a size of arrows(for example, to avoid overlap).
- Returns
- figure
Figure object contains interactive streamlines or vectors.