-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Api deprecate cmap functions #23668
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Api deprecate cmap functions #23668
Changes from all commits
1e40f41
a17f4f3
bf6bb85
bc4b029
4b6c1b1
c2c0026
08ac800
a987e31
d2869b2
014c1ea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Pending deprecation top-level cmap registration and access functions in ``mpl.cm`` | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
As part of a `multi-step process | ||
<https://github.com/matplotlib/matplotlib/issues/20853>`_ we are refactoring | ||
the global state for managing the registered colormaps. | ||
|
||
In Matplotlib 3.5 we added a `.ColormapRegistry` class and exposed an | ||
instance at the top level as ``matplotlib.colormaps``. The existing | ||
top level functions in `matplotlib.cm` (``get_cmap``, ``register_cmap``, | ||
``unregister_cmap``) were changed to be aliases around the same instance. | ||
|
||
In Matplotlib 3.6 we have marked those top level functions as pending | ||
deprecation with the intention of deprecation in Matplotlib 3.7. The | ||
following functions have been marked for pending deprecation: | ||
|
||
- `matplotlib.cm.get_cmap` - use ``matplotlib.colormaps[name]`` instead | ||
- `matplotlib.cm.register_cmap` - use ``matplotlib.colormaps.register`` instead | ||
- `matplotlib.cm.unregister_cmap` - use ``matplotlib.colormaps.unregister`` instead | ||
- ``matplotlib.pyplot.register_cmap`` - use ``matplotlib.colormaps.register`` instead | ||
|
||
The `matplotlib.pyplot.get_cmap` function will stay available for backward compatibility. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,6 +64,7 @@ Plotting commands | |
gcf | ||
gci | ||
get | ||
get_cmap | ||
get_figlabels | ||
get_fignums | ||
getp | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Colormap method for creating a different lookup table size | ||
---------------------------------------------------------- | ||
The new method `.Colormap.resampled` creates a new `.Colormap` instance | ||
with the specified lookup table size. This is a replacement for manipulating | ||
the lookup table size via ``get_cmap``. | ||
|
||
Use:: | ||
|
||
get_cmap(name).resampled(N) | ||
|
||
instead of:: | ||
|
||
get_cmap(name, lut=N) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1220,7 +1220,7 @@ def test_pcolormesh_alpha(): | |
Qy = Y + np.sin(X) | ||
Z = np.hypot(X, Y) / 5 | ||
Z = (Z - Z.min()) / Z.ptp() | ||
vir = plt.get_cmap("viridis", 16) | ||
vir = mpl.colormaps["viridis"].resampled(16) | ||
# make another colormap with varying alpha | ||
colors = vir(np.arange(16)) | ||
colors[:, 3] = 0.5 + 0.5*np.sin(np.arange(16)) | ||
|
@@ -2250,7 +2250,7 @@ def test_contour_hatching(): | |
x, y, z = contour_dat() | ||
fig, ax = plt.subplots() | ||
ax.contourf(x, y, z, 7, hatches=['/', '\\', '//', '-'], | ||
cmap=plt.get_cmap('gray'), | ||
cmap=mpl.colormaps['gray'], | ||
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. Can we just use strings if we aren't using 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. It can, but I was just mechanically changing (a lot of this was done with search-and-relpace) 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've decided to leave this. It makes the test a bit more complicated, but I do not know if we are definitely exercising the ability to pass |
||
extend='both', alpha=0.5) | ||
|
||
|
||
|
@@ -2260,7 +2260,7 @@ def test_contour_colorbar(): | |
|
||
fig, ax = plt.subplots() | ||
cs = ax.contourf(x, y, z, levels=np.arange(-1.8, 1.801, 0.2), | ||
cmap=plt.get_cmap('RdBu'), | ||
cmap=mpl.colormaps['RdBu'], | ||
vmin=-0.6, | ||
vmax=0.6, | ||
extend='both') | ||
|
@@ -2444,7 +2444,7 @@ def test_scatter_edgecolor_RGB(self): | |
@check_figures_equal(extensions=["png"]) | ||
def test_scatter_invalid_color(self, fig_test, fig_ref): | ||
ax = fig_test.subplots() | ||
cmap = plt.get_cmap("viridis", 16) | ||
cmap = mpl.colormaps["viridis"].resampled(16) | ||
cmap.set_bad("k", 1) | ||
# Set a nonuniform size to prevent the last call to `scatter` (plotting | ||
# the invalid points separately in fig_ref) from using the marker | ||
|
@@ -2453,15 +2453,15 @@ def test_scatter_invalid_color(self, fig_test, fig_ref): | |
c=[1, np.nan, 2, np.nan], s=[1, 2, 3, 4], | ||
cmap=cmap, plotnonfinite=True) | ||
ax = fig_ref.subplots() | ||
cmap = plt.get_cmap("viridis", 16) | ||
cmap = mpl.colormaps["viridis"].resampled(16) | ||
ax.scatter([0, 2], [0, 2], c=[1, 2], s=[1, 3], cmap=cmap) | ||
ax.scatter([1, 3], [1, 3], s=[2, 4], color="k") | ||
|
||
@check_figures_equal(extensions=["png"]) | ||
def test_scatter_no_invalid_color(self, fig_test, fig_ref): | ||
# With plotnonfinite=False we plot only 2 points. | ||
ax = fig_test.subplots() | ||
cmap = plt.get_cmap("viridis", 16) | ||
cmap = mpl.colormaps["viridis"].resampled(16) | ||
cmap.set_bad("k", 1) | ||
ax.scatter(range(4), range(4), | ||
c=[1, np.nan, 2, np.nan], s=[1, 2, 3, 4], | ||
|
Uh oh!
There was an error while loading. Please reload this page.