diff --git a/docs/_static/images/plot-with-clim.png b/docs/_static/images/plot-with-clim.png new file mode 100644 index 00000000..a22a4250 Binary files /dev/null and b/docs/_static/images/plot-with-clim.png differ diff --git a/docs/examples/index.rst b/docs/examples/index.rst index 8294604b..45d14cfc 100644 --- a/docs/examples/index.rst +++ b/docs/examples/index.rst @@ -30,3 +30,8 @@ Gallery :width: 200 :class: no-scaled-link + * - :ref:`example-plot-with-clim` + + .. image:: /_static/images/plot-with-clim.png + :width: 200 + :class: no-scaled-link diff --git a/docs/examples/plot-with-clim.py b/docs/examples/plot-with-clim.py new file mode 100644 index 00000000..6067f34e --- /dev/null +++ b/docs/examples/plot-with-clim.py @@ -0,0 +1,30 @@ +import cartopy.crs +import emsarray +import emsarray.plot +from cartopy.feature import GSHHSFeature +from matplotlib import pyplot + +ds = emsarray.tutorial.open_dataset('austen') + +figure = pyplot.figure(figsize=(10, 8), layout='constrained') +axes = figure.add_subplot(projection=cartopy.crs.PlateCarree()) +axes.set_aspect('equal', adjustable='datalim') + +polys = ds.ems.make_poly_collection( + ds['eta'].isel(record=0), + clim=(-3, 3), edgecolor='face', + cmap='Spectral', +) +axes.add_collection(polys) +figure.colorbar(polys, ax=axes, location='right', label="metres") + +coast = GSHHSFeature(scale='intermediate') +axes.add_feature(coast, facecolor='linen', edgecolor='darkgrey', linewidth=0.5) + +axes.autoscale() +axes.set_title("Sea surface height deviation") +axes.set_facecolor('aliceblue') + +figure.savefig('plot-with-clim.png') + +pyplot.show(block=True) diff --git a/docs/examples/plot-with-clim.rst b/docs/examples/plot-with-clim.rst new file mode 100644 index 00000000..79f600b7 --- /dev/null +++ b/docs/examples/plot-with-clim.rst @@ -0,0 +1,23 @@ +.. _example-plot-with-clim: + +=============================== +Plot with specified data limits +=============================== + +The :meth:`Convention.make_poly_collection()` method passes all keyword arguments +on to :class:`~matplotlib.collections.PolyCollection`. +This can be used to customise the appearance of the collection +and to set parameters such as `clim`: + +.. image:: /_static/images/plot-with-clim.png + :alt: A plot of sea surface height deviation from the Australia wide AUSTEn dataset. + The limits of the colour bar have been constrianed to (-3, 3). + +Code +==== + +:download:`Download plot-with-clim.py example `. + +.. literalinclude:: plot-with-clim.py + :language: python + diff --git a/docs/releases/development.rst b/docs/releases/development.rst index e50f5b48..3ffd7699 100644 --- a/docs/releases/development.rst +++ b/docs/releases/development.rst @@ -5,3 +5,6 @@ Next release (in development) * Fixed issues with detecting topology variables in SHOC datasets where some variables are lacking a `standard_name` (:issue:`178`, :pr:`180`). * Updated the tests to be compatible with the latest xarray versions (:pr:`182`). +* Added an example to the documentation showing + :ref:`how to set the clim parameter in plots ` + (:pr:`179`).