Matpltolib seems to apply the tab10
colormap by default.
How can I change the default colormap and use a different colormap instead, e.g. Set3
?
I tried plt.rcParams['image.cmap'] = 'Set3'
and plt.set_cmap('Set3')
as suggested in this answer. However, non of the two options worked.
import matplotlib.pyplot as plt
import numpy as np
plt.rcParams['image.cmap']='Set3'
plt.set_cmap('Set3')
species = ('Adelie', 'Chinstrap', 'Gentoo')
sex_counts = {
'Male': np.array([73, 34, 61]),
'Female': np.array([73, 34, 58]),
}
width = 0.6 # the width of the bars: can also be len(x) sequence
fig, ax = plt.subplots()
bottom = np.zeros(3)
for sex, sex_count in sex_counts.items():
p = ax.bar(species, sex_count, width, label=sex, bottom=bottom)
bottom += sex_count
ax.bar_label(p, label_type='center')
ax.set_title('Number of penguins by sex')
ax.legend()
plt.show()