Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7d7fef8

Browse files
authored
Merge pull request #29501 from meeseeksmachine/auto-backport-of-pr-29478-on-v3.10.0-doc
Backport PR #29478 on branch v3.10.0-doc (DOC: Added blurb for colorizer objects in what's new for 3.10)
2 parents ca8f098 + 874af20 commit 7d7fef8

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

doc/users/prev_whats_new/whats_new_3.10.0.rst

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,62 @@ the ``set_data`` method, enabling e.g. resampling
292292
fig.savefig("after.png")
293293
294294
295+
``matplotlib.colorizer.Colorizer`` as container for ``norm`` and ``cmap``
296+
-------------------------------------------------------------------------
297+
298+
`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.
299+
300+
In the following example the norm and cmap are changed on multiple plots simultaneously:
301+
302+
303+
.. plot::
304+
:include-source: true
305+
:alt: Example use of a matplotlib.colorizer.Colorizer object
306+
307+
import matplotlib.pyplot as plt
308+
import matplotlib as mpl
309+
import numpy as np
310+
311+
x = np.linspace(-2, 2, 50)[np.newaxis, :]
312+
y = np.linspace(-2, 2, 50)[:, np.newaxis]
313+
im_0 = 1 * np.exp( - (x**2 + y**2 - x * y))
314+
im_1 = 2 * np.exp( - (x**2 + y**2 + x * y))
315+
316+
colorizer = mpl.colorizer.Colorizer()
317+
fig, axes = plt.subplots(1, 2, figsize=(6, 2))
318+
cim_0 = axes[0].imshow(im_0, colorizer=colorizer)
319+
fig.colorbar(cim_0)
320+
cim_1 = axes[1].imshow(im_1, colorizer=colorizer)
321+
fig.colorbar(cim_1)
322+
323+
colorizer.vmin = 0.5
324+
colorizer.vmax = 2
325+
colorizer.cmap = 'RdBu'
326+
327+
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:
328+
329+
.. plot::
330+
:include-source: true
331+
:alt: Example of how artists that share a ``colorizer`` have coupled colormaps
332+
333+
import matplotlib.pyplot as plt
334+
import matplotlib as mpl
335+
import numpy as np
336+
337+
x = np.linspace(-2, 2, 50)[np.newaxis, :]
338+
y = np.linspace(-2, 2, 50)[:, np.newaxis]
339+
im_0 = 1 * np.exp( - (x**2 + y**2 - x * y))
340+
im_1 = 2 * np.exp( - (x**2 + y**2 + x * y))
341+
342+
fig, axes = plt.subplots(1, 2, figsize=(6, 2))
343+
344+
cim_0 = axes[0].imshow(im_0, cmap='RdBu', vmin=0.5, vmax=2)
345+
fig.colorbar(cim_0)
346+
cim_1 = axes[1].imshow(im_1, colorizer=cim_0.colorizer)
347+
fig.colorbar(cim_1)
348+
349+
cim_1.cmap = 'rainbow'
350+
295351
3D plotting improvements
296352
========================
297353

0 commit comments

Comments
 (0)