diff --git a/continuous-integration/requirements-3.12.txt b/continuous-integration/requirements-3.12.txt index 0844ebbb..e5ad7c9e 100644 --- a/continuous-integration/requirements-3.12.txt +++ b/continuous-integration/requirements-3.12.txt @@ -184,7 +184,7 @@ pytest==9.0.1 # pytest-mpl pytest-cov==7.0.0 # via emsarray (pyproject.toml) -pytest-mpl==0.17.0 +pytest-mpl==0.18.0 # via emsarray (pyproject.toml) python-dateutil==2.9.0.post0 # via diff --git a/continuous-integration/requirements-3.13.txt b/continuous-integration/requirements-3.13.txt index 5f1efc5f..587558e5 100644 --- a/continuous-integration/requirements-3.13.txt +++ b/continuous-integration/requirements-3.13.txt @@ -184,7 +184,7 @@ pytest==9.0.1 # pytest-mpl pytest-cov==7.0.0 # via emsarray (pyproject.toml) -pytest-mpl==0.17.0 +pytest-mpl==0.18.0 # via emsarray (pyproject.toml) python-dateutil==2.9.0.post0 # via diff --git a/continuous-integration/requirements-3.14.txt b/continuous-integration/requirements-3.14.txt index dfe33507..f1ff285c 100644 --- a/continuous-integration/requirements-3.14.txt +++ b/continuous-integration/requirements-3.14.txt @@ -184,7 +184,7 @@ pytest==9.0.1 # pytest-mpl pytest-cov==7.0.0 # via emsarray (pyproject.toml) -pytest-mpl==0.17.0 +pytest-mpl==0.18.0 # via emsarray (pyproject.toml) python-dateutil==2.9.0.post0 # via diff --git a/docs/_static/images/gbr4_temp.png b/docs/_static/images/gbr4_temp.png index 2efd122d..d222d68e 100644 Binary files a/docs/_static/images/gbr4_temp.png and b/docs/_static/images/gbr4_temp.png differ diff --git a/docs/_static/images/kgari-path.png b/docs/_static/images/kgari-path.png index 7b2c11cc..15123101 100644 Binary files a/docs/_static/images/kgari-path.png and b/docs/_static/images/kgari-path.png differ diff --git a/docs/_static/images/kgari-transect.png b/docs/_static/images/kgari-transect.png index ce442d8a..c5693ccc 100644 Binary files a/docs/_static/images/kgari-transect.png and b/docs/_static/images/kgari-transect.png differ diff --git a/docs/examples/kgari-transect.py b/docs/examples/kgari-transect.py index 537352b1..fb958ec7 100644 --- a/docs/examples/kgari-transect.py +++ b/docs/examples/kgari-transect.py @@ -4,7 +4,7 @@ import emsarray from emsarray import plot, transect -dataset_url = 'https://thredds.nci.org.au/thredds/dodsC/fx3/model_data/gbr4_bgc_GBR4_H2p0_B2p0_Chyd_Dcrt.ncml' +dataset_url = 'https://thredds.nci.org.au/thredds/dodsC/fx3/gbr4_H4p0_ABARRAr2_OBRAN2020_FG2Gv3_Dhnd/gbr4_simple_2022-10-31.nc' dataset = emsarray.open_dataset(dataset_url).isel(time=-1) dataset = dataset.ems.select_variables(['botz', 'temp']) @@ -34,7 +34,9 @@ dataset, line, dataset['temp'], figsize=(7.9, 3), bathymetry=dataset['botz'], - landmarks=landmarks) + landmarks=landmarks, + title="Temperature", + cmap='Oranges_r') figure.savefig('kgari-transect.png') # Plot the path of the transect @@ -43,14 +45,15 @@ axes.set_aspect(aspect='equal', adjustable='datalim') axes.set_title('Transect path') axes.add_collection(dataset.ems.make_poly_collection( - dataset['botz'], cmap='Blues_r', edgecolor='face', + dataset['botz'], cmap='Blues', clim=(0, 2000), edgecolor='face', linewidth=0.5, zorder=0)) +axes = figure.axes[0] +axes.set_extent(plot.bounds_to_extent(line.envelope.buffer(0.2).bounds)) +axes.plot(*line.coords.xy, zorder=2, c='orange', linewidth=4) + plot.add_coast(axes, zorder=1) plot.add_gridlines(axes) plot.add_landmarks(axes, landmarks) -axes = figure.axes[0] -axes.set_extent(plot.bounds_to_extent(line.envelope.buffer(0.2).bounds)) -axes.plot(*line.coords.xy, zorder=2) figure.savefig('kgari-path.png') pyplot.show(block=True) diff --git a/docs/releases/development.rst b/docs/releases/development.rst index 48476ebf..a7c16b3a 100644 --- a/docs/releases/development.rst +++ b/docs/releases/development.rst @@ -24,3 +24,7 @@ Next release (in development) which is a backwards incompatible change but is difficult to add meaningful backwards compatible support (:issue:`109`, :pr:`204`) +* Use default matplotlib colour map when plotting instead of "jet". + In practice this will usually be "viridis" + unless the user has changed their local defaults + (:pr:`206`). diff --git a/pyproject.toml b/pyproject.toml index b47799eb..ffeca8f2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -89,12 +89,6 @@ where = ["src"] mypkg = ["py.typed"] [tool.pytest.ini_options] -addopts = [ - # TODO Work around till the mpl-baseline-path ini option is included in the - # next pytest-mpl release. - "--mpl-baseline-path", "tests/baseline_images", -] - testpaths = ["tests"] filterwarnings = [ "error", @@ -106,9 +100,8 @@ markers = [ ] mpl-use-full-test-name = true -# TODO This option will be included in the next version of pytest-mpl. -# Till then, it is added using addopts above -# mpl-baseline-path = "tests/baseline_images" +mpl-baseline-path = "tests/baseline_images" +mpl-default-style = "default" [tool.mypy] python_version = "3.12" diff --git a/src/emsarray/plot.py b/src/emsarray/plot.py index 3305d6ca..72007c16 100644 --- a/src/emsarray/plot.py +++ b/src/emsarray/plot.py @@ -130,7 +130,7 @@ def add_landmarks( # Plot the temperature temperature = dataset.ems.make_poly_collection( dataset['temp'].isel(time=0, k=-1), - cmap='jet', edgecolor='face', zorder=0) + cmap='viridis', edgecolor='face', zorder=0) axes.add_collection(temperature) figure.colorbar(temperature, label='°C') @@ -321,7 +321,7 @@ def plot_on_figure( if scalar is not None: # Plot a scalar variable on the polygons using a colour map collection = convention.make_poly_collection( - scalar, cmap='jet', edgecolor='face') + scalar, edgecolor='face') axes.add_collection(collection) units = scalar.attrs.get('units') figure.colorbar(collection, ax=axes, location='right', label=units) @@ -437,7 +437,7 @@ def animate_on_figure( # Plot a scalar variable on the polygons using a colour map scalar_values = convention.ravel(scalar).values[:, convention.mask] collection = convention.make_poly_collection( - cmap='jet', edgecolor='face', + edgecolor='face', clim=(numpy.nanmin(scalar_values), numpy.nanmax(scalar_values))) axes.add_collection(collection) collection.set_animated(True) diff --git a/src/emsarray/transect.py b/src/emsarray/transect.py index 45b31d17..725fa5c8 100644 --- a/src/emsarray/transect.py +++ b/src/emsarray/transect.py @@ -8,7 +8,7 @@ import shapely import xarray from cartopy import crs -from matplotlib import animation, colormaps, pyplot +from matplotlib import animation, pyplot from matplotlib.artist import Artist from matplotlib.axes import Axes from matplotlib.collections import PolyCollection @@ -558,7 +558,7 @@ def plot_on_figure( trim_nans: bool = True, clamp_to_surface: bool = True, bathymetry: xarray.DataArray | None = None, - cmap: str | Colormap = 'jet', + cmap: str | Colormap | None = None, clim: tuple[float, float] | None = None, ocean_floor_colour: str = 'black', landmarks: list[Landmark] | None = None, @@ -620,7 +620,7 @@ def animate_on_figure( trim_nans: bool = True, clamp_to_surface: bool = True, bathymetry: xarray.DataArray | None = None, - cmap: str | Colormap = 'jet', + cmap: str | Colormap | None = None, clim: tuple[float, float] | None = None, ocean_floor_colour: str = 'black', landmarks: list[Landmark] | None = None, @@ -717,7 +717,7 @@ def _plot_on_figure( trim_nans: bool = True, clamp_to_surface: bool = True, bathymetry: xarray.DataArray | None = None, - cmap: str | Colormap = 'jet', + cmap: str | Colormap | None = None, clim: tuple[float, float] | None = None, ocean_floor_colour: str = 'black', landmarks: list[Landmark] | None = None, @@ -774,8 +774,7 @@ def _plot_on_figure( if title is not None: axes.set_title(title) - if isinstance(cmap, str): - cmap = colormaps[cmap].copy() + cmap = pyplot.get_cmap(cmap).copy() cmap.set_bad(ocean_floor_colour) # Find a min/max from the data if clim isn't provided and the data array is not empty. diff --git a/tests/baseline_images/tests.test_plot.test_plot.png b/tests/baseline_images/tests.test_plot.test_plot.png index 9abce233..fee22f60 100644 Binary files a/tests/baseline_images/tests.test_plot.test_plot.png and b/tests/baseline_images/tests.test_plot.test_plot.png differ diff --git a/tests/baseline_images/tests.test_transect.test_plot.png b/tests/baseline_images/tests.test_transect.test_plot.png index bbfaf5fb..401ee763 100644 Binary files a/tests/baseline_images/tests.test_transect.test_plot.png and b/tests/baseline_images/tests.test_transect.test_plot.png differ diff --git a/tests/baseline_images/tests.test_transect.test_plot_no_intersection.png b/tests/baseline_images/tests.test_transect.test_plot_no_intersection.png index 0581c1f5..9fcd3110 100644 Binary files a/tests/baseline_images/tests.test_transect.test_plot_no_intersection.png and b/tests/baseline_images/tests.test_transect.test_plot_no_intersection.png differ