Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

MNT: Re-add matplotlib.cm.get_cmap#28355

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

Merged
ksunden merged 1 commit intomatplotlib:mainfromtimhoffm:get_cmap
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletionslib/matplotlib/cm.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -239,6 +239,44 @@
globals().update(_colormaps)


# This is an exact copy of pyplot.get_cmap(). It was removed in 3.9, but apparently
# caused more user trouble than expected. Re-added for 3.9.1 and extended the
# deprecation period for two additional minor releases.
@_api.deprecated(
'3.7',
removal='3.11',
alternative="``matplotlib.colormaps[name]`` or ``matplotlib.colormaps.get_cmap()``"
" or ``pyplot.get_cmap()``"
)
def get_cmap(name=None, lut=None):
"""
Get a colormap instance, defaulting to rc values if *name* is None.

Parameters
----------
name : `~matplotlib.colors.Colormap` or str or None, default: None
If a `.Colormap` instance, it will be returned. Otherwise, the name of
a colormap known to Matplotlib, which will be resampled by *lut*. The
default, None, means :rc:`image.cmap`.
lut : int or None, default: None
If *name* is not already a Colormap instance and *lut* is not None, the
colormap will be resampled to have *lut* entries in the lookup table.

Returns
-------
Colormap
"""
if name is None:
name = mpl.rcParams['image.cmap']

Check warning on line 270 in lib/matplotlib/cm.py

View check run for this annotation

Codecov/ codecov/patch

lib/matplotlib/cm.py#L270

Added line #L270 was not covered by tests
if isinstance(name, colors.Colormap):
return name
_api.check_in_list(sorted(_colormaps), name=name)

Check warning on line 273 in lib/matplotlib/cm.py

View check run for this annotation

Codecov/ codecov/patch

lib/matplotlib/cm.py#L272-L273

Added lines #L272 - L273 were not covered by tests
if lut is None:
return _colormaps[name]

Check warning on line 275 in lib/matplotlib/cm.py

View check run for this annotation

Codecov/ codecov/patch

lib/matplotlib/cm.py#L275

Added line #L275 was not covered by tests
else:
return _colormaps[name].resampled(lut)

Check warning on line 277 in lib/matplotlib/cm.py

View check run for this annotation

Codecov/ codecov/patch

lib/matplotlib/cm.py#L277

Added line #L277 was not covered by tests


def _auto_norm_from_scale(scale_cls):
"""
Automatically generate a norm class from *scale_cls*.
Expand Down
2 changes: 2 additions & 0 deletionslib/matplotlib/cm.pyi
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,6 +19,8 @@ class ColormapRegistry(Mapping[str, colors.Colormap]):

_colormaps: ColormapRegistry = ...

def get_cmap(name: str | colors.Colormap | None = ..., lut: int | None = ...) -> colors.Colormap: ...

class ScalarMappable:
cmap: colors.Colormap | None
colorbar: Colorbar | None
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp