8000 [Doc]: Preferred way of specifying colormaps via `cmap` · Issue #28915 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
[Doc]: Preferred way of specifying colormaps via cmap #28915
Closed
@timhoffm

Description

@timhoffm

Documentation Link

No response

Problem

We have three four ways:

  1. cmap="magma"
  2. cmap=plt.cm.magma
  3. cmap=plt.colormaps["magma"]
  4. cmap=plt.get_cmap("magma")

Suggested improvement

I'd like to advertise the str version, because it's very readable and less to type. Disadvantage is that you could mis-type (but we have str parameter all over the place) and that you have to separately learn one of the others if you need the colormap explicitly.

I'd like to down-prioritize the plt.cm.* version. While it's too widely used so that we cannot deprecate, having the colormaps as names on the module level does not scale. It only works for builtin colormaps but not for ones that are registered by the user.

So the recommendation would be:

  • Use str colormap names on cmap arguments.
  • Use plt.colormaps[name] to get the colormap instance.

Noted here: https://matplotlib.org/devdocs/users/next_whats_new/diverging_colormaps.html, which should be changed if we agree on the recommendation.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0