I have the following code:
import matplotlib.pyplot as plt
plt.cm.set_cmap("Blues")
This gives me an error:
Traceback (most recent call last):
File ".\lorenz_explorer.py", line 12, in <module>
plt.cm.set_cmap("Blues")
AttributeError: module 'matplotlib.cm' has no attribute 'set_cmap'
My matplotlib version is 3.3.1, and the function certainly exists in the documentation for 3.3.1: Link
Then am I doing something wrong or is this a bug? Do I need to import matplotlib.cm
separately or something along those lines?
As the documentation link you provide shows, the name of the function is matplotlib.pyplot.set_cmap
, not matplotlib.pyplot.cm.set_cmap
. So you can call it with plt.set_cmap("Blues")
.
In other words, the function is not part of the cm
library, which is somewhat counter-intuitive.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.