Description
Documentation Link
No response
Problem
We have three four ways:
cmap="magma"
cmap=plt.cm.magma
cmap=plt.colormaps["magma"]
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.