Reputation: 23
I would like to change the default colormap for pyplots from 'viridis' to 'Dark2'.
I tried:
changing the 'image.cmap' line in the matplotlibrc file
mpl.rcParams['image.cmap'] = 'Dark2'
mpl.pyplot.set_cmap('Dark2')
pyplot.set_cmap('Dark2')
Somehow none of these attempts worked. I also tried restarting the kernel afterwards and also restartet spyder itself but nothing changed. Now Im out of ideas.
import matplotlib as mpl
from matplotlib import pyplot
mpl.rcParams['image.cmap'] = 'Dark2'
mpl.pyplot.set_cmap('Dark2')
pyplot.set_cmap('Dark2')
I am always ending up with the default colors of the viridis colormap which starts with a blueish color and 2nd on orange one. I would like to see the green color from Dark2 first and than the orange one.
Appreciate your help !
cheers, Gerrit
Upvotes: 1
Views: 6503
Reputation: 8228
I don't think plt.set_cmap
works for your use case. Here are two options that should.
Use Seaborn's helper:
import seaborn as sns
sns.set_palette('Dark2')
Use Maplotlib rcParams:
from cycler import cycler
from matplotlib import pyplot as plt
plt.rcParams['axes.prop_cycle'] = cycler('color', plt.get_cmap('Dark2').colors)
Upvotes: 2
Reputation: 1227
You can use matplotlib.pyplot.set_cmap is the way to change the default colormap. If you run the code below, you should see the 'Dark2' colormap.
import matplotlib.pyplot as plt
import numpy as np
plt.set_cmap('Dark2')
plt.imshow(np.random.random((20, 20)))
plt.colorbar()
plt.show()
Upvotes: 0