emsarray.plot
emsarray.plot#
- emsarray.plot.add_coast(axes, **kwargs)#
Add coastlines to an
Axes
. Some default styles are applied: the land polygons are light grey and semi-transparent, and the coastlines are opaque dark grey.- Parameters
axes (
matplotlib.axes.Axes
) – The axes to add the coastline to**kwargs – Passed to
Axes.add_feature()
.
- emsarray.plot.bounds_to_extent(bounds)#
Convert a Shapely bounds tuple to a matplotlib extents.
A Shapely bounds is a tuple of (min x, min y, max x, max y), while a Matplotlib extent is a list of (min x, max x, min y, max y).
Example
import cartopy.crs as ccrs import matplotlib.pyplot as plt from emsarray.plot import bounds_to_extent, polygon_to_patch from shapely.geometry import Polygon polygon = Polygon([ (148.30, -40.75), (146.47, -41.19), (144.67, -40.62), (146.05, -43.53), (146.87, -43.60), (148.30, -40.75), ]) figure = plt.figure(figsize=(10, 8), dpi=100) axes = plt.subplot(projection=ccrs.PlateCarree()) axes.set_extent(bounds_to_extent(polygon.buffer(0.1).bounds)) axes.add_patch(polygon_to_patch(polygon)) figure.show()
- emsarray.plot.polygon_to_patch(polygon, **kwargs)#
Convert a
shapely.geometry.Polygon
to amatplotlib.patches.Polygon
.
- emsarray.plot.polygons_to_patch_collection(polygons, **kwargs)#
Convert a list of Shapely
Polygons
to a matplotlibPatchCollection
.- Parameters
polygons (
iterable
of Polygon) – The polygons for the patch collection**kwargs (
Any
) – Keyword arguments to pass to the PatchCollection constructor.
- Returns
matplotlib.collections.PatchCollection
– The PatchCollection made up of the polygons passed in.
- emsarray.plot.plot_on_figure(figure, format, *, scalar=None, vector=None, title=None, projection=None)#
Plot a
DataArray
on amatplotlib
Figure
.- Parameters
figure – The
Figure
instace to plot on.format – The
Format
instance of the dataset. This is used to build the polygons and vector quivers.scalar (
xarray.DataArray
, optional) – The data to plot as anxarray.DataArray
. This will be passed toFormat.make_patch_collection()
.vector (
tuple
ofnumpy.ndarray
, optional) – The u and v components of a vector field as a tuple ofxarray.DataArray
. These will be passed toFormat.make_quiver()
.title (
str
, optional) – The title of the plot. Optional.projection (
Projection
) – The projection to use when plotting. Optional, defaults toPlateCarree
. This is different to the coordinate reference system for the data, which is defined inFormat.data_crs
.
- emsarray.plot.animate_on_figure(figure, format, *, coordinate, scalar=None, vector=None, title=None, projection=None, interval=1000, repeat=True)#
Plot a
xarray.DataArray
on amatplotlib
Figure
as aFuncAnimation
.- Parameters
figure (
matplotlib.figure.Figure
) – TheFigure
instace to plot on.format – The
Format
instance of the dataset. This is used to build the polygons and vector quivers.coordinate (
xarray.DataArray
) – The coordinate values to vary across frames in the animation.scalar (
xarray.DataArray
, optional) – The data to plot as anxarray.DataArray
. This will be passed toFormat.make_patch_collection()
. It should have horizontal dimensions appropriate for this format, and a dimension matching thecoordinate
parameter.vector (
tuple
ofnumpy.ndarray
, optional) – The u and v components of a vector field as a tuple ofxarray.DataArray
. These will be passed toFormat.make_quiver()
. These should have horizontal dimensions appropriate for this format, and a dimension matching thecoordinate
parameter.title (
str
orcallable
, optional) –The title for each frame of animation. Optional, will default to the coordinate value for each frame.
If this is a string,
str.format()
will be called with the coordinate value for each frame.If this is a callable, it will be called with the coordinate value for each frame, and it should return a string for the title.
projection (
Projection
) – The projection to use when plotting. Optional, defaults toPlateCarree
. This is different to the coordinate reference system for the data, which is defined inFormat.data_crs
.interval (
int
) – The interval between frames of animationrepeat (
{True, False, 'cycle', 'bounce'}
) – Whether to repeat the animation or not.True
and'cycle'
will play the animation on loop forever.'bounce'
will play the animation forward, then backward, then repeat.False
will play the animation once then stop.
- Returns