Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Update to docs with regards to colorbar and colorizer#30112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -11,15 +11,16 @@ | ||||||
value *x* in the image). | ||||||
If we want one colorbar to be representative for multiple images, we have | ||||||
to explicitly ensure consistent data coloring by using the same | ||||||
data-to-color pipeline for all the images. We ensure this by explicitly | ||||||
creating a `matplotlib.colorizer.Colorizer` object that we pass to all | ||||||
the image plotting methods. | ||||||
""" | ||||||
import matplotlib.pyplot as plt | ||||||
import numpy as np | ||||||
import matplotlibas mpl | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I think we don't explicitly support or encourage chained usage of subpackages, I.e. mpl.this.that | ||||||
np.random.seed(19680801) | ||||||
@@ -31,12 +32,13 @@ | ||||||
fig, axs = plt.subplots(2, 2) | ||||||
fig.suptitle('Multiple images') | ||||||
# create a single norm and colorizer to be shared across all images | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Suggested change
| ||||||
norm = mpl.colors.Normalize(vmin=np.min(datasets), vmax=np.max(datasets)) | ||||||
colorizer = mpl.colorizer.Colorizer(norm=norm) | ||||||
images = [] | ||||||
for ax, data in zip(axs.flat, datasets): | ||||||
images.append(ax.imshow(data,colorizer=colorizer)) | ||||||
fig.colorbar(images[0], ax=axs, orientation='horizontal', fraction=.1) | ||||||
@@ -45,30 +47,10 @@ | ||||||
# %% | ||||||
# The colors are now kept consistent across all images when changing the | ||||||
# scaling, e.g. through zooming in the colorbar or via the "edit axis, | ||||||
# curves and images parameters" GUI of the Qt backend. Additionally, | ||||||
# if the colormap of the colorizer is changed, (e.g. through the "edit | ||||||
# axis, curves and images parameters" GUI of the Qt backend) this change | ||||||
# propagates to the other plots and the colorbar. | ||||||
# | ||||||
# .. admonition:: References | ||||||
# | ||||||
@@ -77,6 +59,6 @@ | ||||||
# | ||||||
# - `matplotlib.axes.Axes.imshow` / `matplotlib.pyplot.imshow` | ||||||
# - `matplotlib.figure.Figure.colorbar` / `matplotlib.pyplot.colorbar` | ||||||
# - `matplotlib.colorizer.Colorizer` | ||||||
# - `matplotlib.colors.Normalize` | ||||||
# - `matplotlib.cbook.CallbackRegistry.connect` | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I think connect is removed as well |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -8,10 +8,11 @@ | ||
This tutorial shows how to build and customize standalone colorbars, i.e. | ||
without an attached plot. | ||
A `~.Figure.colorbar` needs a "mappable" (`matplotlib.colorizer.ColorizingArtist`) | ||
object (typically, an image) which contains a colorizer | ||
(`matplotlib.colorizer.Colorizer`) that holds the data-to-color pipeline (norm and | ||
colormap). In order to create a colorbar without an attached image, one can instead | ||
use a `.ColorizingArtist` with no associated data. | ||
Comment on lines +11 to +15 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I think you can be more straightforward. ColorizingArtist is the base class for everything that "can be colormapped". Directly instruct to create the base class and pass it to colorbar. This the detour "typically subclasses with data, like image, but you can create without data" is not needed for the context of creating a standalone colorbar. | ||
""" | ||
import matplotlib.pyplot as plt | ||
@@ -23,17 +24,21 @@ | ||
# ------------------------- | ||
# Here, we create a basic continuous colorbar with ticks and labels. | ||
# | ||
# The arguments to the `~.Figure.colorbar` call are a `.ColorizingArtist`, | ||
# the axes where the colorbar should be drawn, and the colorbar's orientation. | ||
# To crate a `.ColorizingArtist` one must first make `.Colorizer` that holds the | ||
# desired *norm* and *cmap*. | ||
# | ||
# | ||
# For more information see the `~matplotlib.colorbar` API. | ||
fig, ax = plt.subplots(figsize=(6, 1), layout='constrained') | ||
norm = mpl.colors.Normalize(vmin=5, vmax=10) | ||
colorizer = mpl.colorizer.Colorizer(norm=norm, cmap="cool") | ||
fig.colorbar(mpl.colorizer.ColorizingArtist(colorizer), | ||
cax=ax, orientation='horizontal', label='Some Units') | ||
# %% | ||
@@ -47,7 +52,9 @@ | ||
fig, ax = plt.subplots(layout='constrained') | ||
colorizer = mpl.colorizer.Colorizer(norm=mpl.colors.Normalize(0, 1), cmap='magma') | ||
fig.colorbar(mpl.colorizer.ColorizingArtist(colorizer), | ||
ax=ax, orientation='vertical', label='a colorbar label') | ||
# %% | ||
@@ -65,7 +72,9 @@ | ||
bounds = [-1, 2, 5, 7, 12, 15] | ||
norm = mpl.colors.BoundaryNorm(bounds, cmap.N, extend='both') | ||
colorizer = mpl.colorizer.Colorizer(norm=norm, cmap='viridis') | ||
fig.colorbar(mpl.colorizer.ColorizingArtist(colorizer), | ||
cax=ax, orientation='horizontal', | ||
label="Discrete intervals with extend='both' keyword") | ||
@@ -94,8 +103,10 @@ | ||
bounds = [1, 2, 4, 7, 8] | ||
norm = mpl.colors.BoundaryNorm(bounds, cmap.N) | ||
colorizer = mpl.colorizer.Colorizer(norm=norm, cmap=cmap) | ||
fig.colorbar( | ||
mpl.colorizer.ColorizingArtist(colorizer), | ||
cax=ax, orientation='horizontal', | ||
extend='both', | ||
spacing='proportional', | ||
@@ -116,8 +127,10 @@ | ||
bounds = [-1.0, -0.5, 0.0, 0.5, 1.0] | ||
norm = mpl.colors.BoundaryNorm(bounds, cmap.N) | ||
colorizer = mpl.colorizer.Colorizer(norm=norm, cmap=cmap) | ||
fig.colorbar( | ||
mpl.colorizer.ColorizingArtist(colorizer), | ||
cax=ax, orientation='horizontal', | ||
extend='both', extendfrac='auto', | ||
spacing='uniform', | ||
Uh oh!
There was an error while loading.Please reload this page.