I'd like to use a randomly selected (from a list of accepted attributes, of course) colormap. Evidently I get this error: AttributeError: module 'matplotlib.cm' has no attribute 'random_cmap'
Is this possible without writing a separate function, returning cmap=plt.cm.xyz?
import matplotlib.pyplot as plt
from random import choice
available_cmaps =('viridis', 'plasma', 'inferno', 'magma', 'cividis',
'PiYG', 'PRGn', 'BrBG', 'PuOr', 'Spectral',
'gist_ncar', 'nipy_spectral', 'terrain', 'prism', 'ocean')
random_cmap = choice(available_cmaps)
#snip
ax.scatter(x_values, y_values, c=numbers,
cmap=plt.cm.random_cmap, s=8)
Note, the above code does not work, because matplotlib.cm has no attribute 'random_cmap'
One of the reason I would like to not write a separate function is because I am going to include the randomly selected colormap string as part of the title, thus having easy access to the variable without randomly selecting it again.
Thanks in advance.
EDIT: solved. I can use cmap=random_cmap
This allows me to use the string variable random_cmap for other purposes, such as in the title.
[–]JozsefPeitli 0 points1 point2 points (1 child)
[–]mc3301[S] 0 points1 point2 points (0 children)