From 5d3821dafe53ff2678fa3b44bfa15fefd14b46a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Trygve=20Magnus=20R=C3=A6der?= Date: Fri, 17 Jan 2025 12:08:44 +0100 Subject: [PATCH 1/3] Added blurb for colorizer objects in what's new for 3.10 --- doc/users/prev_whats_new/whats_new_3.10.0.rst | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/doc/users/prev_whats_new/whats_new_3.10.0.rst b/doc/users/prev_whats_new/whats_new_3.10.0.rst index 3d5436bc4f12..5eac26b074c5 100644 --- a/doc/users/prev_whats_new/whats_new_3.10.0.rst +++ b/doc/users/prev_whats_new/whats_new_3.10.0.rst @@ -292,6 +292,62 @@ the ``set_data`` method, enabling e.g. resampling fig.savefig("after.png") +Added ``matplotlib.colorizer.Colorizer`` as a container for ``norm`` and ``cmap`` +------------------------------------------------------------------------------- + +Plotting methods that support the ``norm`` and ``cmap`` keywords now additionally accepts the ``colorizer`` keyword supporting `matplotlib.colorizer.Colorizer` objects. This allows for easier re-use of a data-to-color pipeline. + +In the following example the norm and cmap are changed on multiple plots simultaneously: + + +.. plot:: + :include-source: true + :alt: Example use of a matplotlib.colorizer.Colorizer object + + import matplotlib.pyplot as plt + import matplotlib as mpl + import numpy as np + + x = np.linspace(-2, 2, 50)[np.newaxis, :] + y = np.linspace(-2, 2, 50)[:, np.newaxis] + im_0 = 1 * np.exp( - (x**2 + y**2 - x * y)) + im_1 = 2 * np.exp( - (x**2 + y**2 + x * y)) + + colorizer = mpl.colorizer.Colorizer() + fig, axes = plt.subplots(1, 2, figsize=(6, 2)) + cim_0 = axes[0].imshow(im_0, colorizer=colorizer) + fig.colorbar(cim_0) + cim_1 = axes[1].imshow(im_1, colorizer=colorizer) + fig.colorbar(cim_1) + + colorizer.vmin = 0.5 + colorizer.vmax = 2 + colorizer.cmap = 'RdBu' + +All plotting methods that use a data-to-color pipeline now create a colorizer object if one is not provided. This can be re-used in by subsequent artists such that they will share a single data-to-color pipeline: + +.. plot:: + :include-source: true + :alt: Example of how artists that share a ``colorizer`` have coupled colormaps + + import matplotlib.pyplot as plt + import matplotlib as mpl + import numpy as np + + x = np.linspace(-2, 2, 50)[np.newaxis, :] + y = np.linspace(-2, 2, 50)[:, np.newaxis] + im_0 = 1 * np.exp( - (x**2 + y**2 - x * y)) + im_1 = 2 * np.exp( - (x**2 + y**2 + x * y)) + + fig, axes = plt.subplots(1, 2, figsize=(6, 2)) + + cim_0 = axes[0].imshow(im_0, cmap='RdBu', vmin=0.5, vmax=2) + fig.colorbar(cim_0) + cim_1 = axes[1].imshow(im_1, colorizer=cim_0.colorizer) + fig.colorbar(cim_1) + + cim_1.cmap = 'rainbow' + 3D plotting improvements ======================== From 1d98f42ebcadfafff6792de34e6a771ee7148a74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Trygve=20Magnus=20R=C3=A6der?= Date: Fri, 17 Jan 2025 14:24:44 +0100 Subject: [PATCH 2/3] Update doc/users/prev_whats_new/whats_new_3.10.0.rst Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> --- doc/users/prev_whats_new/whats_new_3.10.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/users/prev_whats_new/whats_new_3.10.0.rst b/doc/users/prev_whats_new/whats_new_3.10.0.rst index 5eac26b074c5..85ecf4fad575 100644 --- a/doc/users/prev_whats_new/whats_new_3.10.0.rst +++ b/doc/users/prev_whats_new/whats_new_3.10.0.rst @@ -295,7 +295,7 @@ the ``set_data`` method, enabling e.g. resampling Added ``matplotlib.colorizer.Colorizer`` as a container for ``norm`` and ``cmap`` ------------------------------------------------------------------------------- -Plotting methods that support the ``norm`` and ``cmap`` keywords now additionally accepts the ``colorizer`` keyword supporting `matplotlib.colorizer.Colorizer` objects. This allows for easier re-use of a data-to-color pipeline. + `matplotlib.colorizer.Colorizer` encapsulates the data-to-color pipeline. It makes reuse of colormapping easier, e.g. across multiple images. Plotting methods that support ``norm`` and ``cmap`` keyword arguments now also accept a ``colorizer`` keyword argument. In the following example the norm and cmap are changed on multiple plots simultaneously: From 8c97f38d883381ef86a58d4309a42d9577cac3b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Trygve=20Magnus=20R=C3=A6der?= Date: Wed, 22 Jan 2025 10:54:41 +0100 Subject: [PATCH 3/3] Text updates to the colorizer blurb from QuLogic Co-authored-by: Elliott Sales de Andrade --- doc/users/prev_whats_new/whats_new_3.10.0.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/users/prev_whats_new/whats_new_3.10.0.rst b/doc/users/prev_whats_new/whats_new_3.10.0.rst index 85ecf4fad575..521b7cd53f51 100644 --- a/doc/users/prev_whats_new/whats_new_3.10.0.rst +++ b/doc/users/prev_whats_new/whats_new_3.10.0.rst @@ -292,10 +292,10 @@ the ``set_data`` method, enabling e.g. resampling fig.savefig("after.png") -Added ``matplotlib.colorizer.Colorizer`` as a container for ``norm`` and ``cmap`` -------------------------------------------------------------------------------- +``matplotlib.colorizer.Colorizer`` as container for ``norm`` and ``cmap`` +------------------------------------------------------------------------- - `matplotlib.colorizer.Colorizer` encapsulates the data-to-color pipeline. It makes reuse of colormapping easier, e.g. across multiple images. Plotting methods that support ``norm`` and ``cmap`` keyword arguments now also accept a ``colorizer`` keyword argument. + `matplotlib.colorizer.Colorizer` encapsulates the data-to-color pipeline. It makes reuse of colormapping easier, e.g. across multiple images. Plotting methods that support *norm* and *cmap* keyword arguments now also accept a *colorizer* keyword argument. In the following example the norm and cmap are changed on multiple plots simultaneously: @@ -324,7 +324,7 @@ In the following example the norm and cmap are changed on multiple plots simulta colorizer.vmax = 2 colorizer.cmap = 'RdBu' -All plotting methods that use a data-to-color pipeline now create a colorizer object if one is not provided. This can be re-used in by subsequent artists such that they will share a single data-to-color pipeline: +All plotting methods that use a data-to-color pipeline now create a colorizer object if one is not provided. This can be re-used by subsequent artists such that they will share a single data-to-color pipeline: .. plot:: :include-source: true