Skip to content

Commit 7f5052a

Browse files
authored
Merge pull request #179 from csiro-coasts/clim-example
Add example showing how to set data limits in a plot
2 parents 8e72d64 + ee049b6 commit 7f5052a

File tree

5 files changed

+61
-0
lines changed

5 files changed

+61
-0
lines changed
209 KB
Loading

docs/examples/index.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,8 @@ Gallery
3030
:width: 200
3131
:class: no-scaled-link
3232

33+
* - :ref:`example-plot-with-clim`
34+
35+
.. image:: /_static/images/plot-with-clim.png
36+
:width: 200
37+
:class: no-scaled-link

docs/examples/plot-with-clim.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import cartopy.crs
2+
import emsarray
3+
import emsarray.plot
4+
from cartopy.feature import GSHHSFeature
5+
from matplotlib import pyplot
6+
7+
ds = emsarray.tutorial.open_dataset('austen')
8+
9+
figure = pyplot.figure(figsize=(10, 8), layout='constrained')
10+
axes = figure.add_subplot(projection=cartopy.crs.PlateCarree())
11+
axes.set_aspect('equal', adjustable='datalim')
12+
13+
polys = ds.ems.make_poly_collection(
14+
ds['eta'].isel(record=0),
15+
clim=(-3, 3), edgecolor='face',
16+
cmap='Spectral',
17+
)
18+
axes.add_collection(polys)
19+
figure.colorbar(polys, ax=axes, location='right', label="metres")
20+
21+
coast = GSHHSFeature(scale='intermediate')
22+
axes.add_feature(coast, facecolor='linen', edgecolor='darkgrey', linewidth=0.5)
23+
24+
axes.autoscale()
25+
axes.set_title("Sea surface height deviation")
26+
axes.set_facecolor('aliceblue')
27+
28+
figure.savefig('plot-with-clim.png')
29+
30+
pyplot.show(block=True)

docs/examples/plot-with-clim.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
.. _example-plot-with-clim:
2+
3+
===============================
4+
Plot with specified data limits
5+
===============================
6+
7+
The :meth:`Convention.make_poly_collection()` method passes all keyword arguments
8+
on to :class:`~matplotlib.collections.PolyCollection`.
9+
This can be used to customise the appearance of the collection
10+
and to set parameters such as `clim`:
11+
12+
.. image:: /_static/images/plot-with-clim.png
13+
:alt: A plot of sea surface height deviation from the Australia wide AUSTEn dataset.
14+
The limits of the colour bar have been constrianed to (-3, 3).
15+
16+
Code
17+
====
18+
19+
:download:`Download plot-with-clim.py example <plot-with-clim.py>`.
20+
21+
.. literalinclude:: plot-with-clim.py
22+
:language: python
23+

docs/releases/development.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ Next release (in development)
55
* Fixed issues with detecting topology variables in SHOC datasets
66
where some variables are lacking a `standard_name` (:issue:`178`, :pr:`180`).
77
* Updated the tests to be compatible with the latest xarray versions (:pr:`182`).
8+
* Added an example to the documentation showing
9+
:ref:`how to set the clim parameter in plots <example-plot-with-clim>`
10+
(:pr:`179`).

0 commit comments

Comments
 (0)