Reputation: 355
The default axis colour cycle in Matplotlib 2.0 is called tab10
:
I want to use a different qualitative colour cycle, such as tab20c
:
I have used this code to change the default axis colour cycle:
import matplotlib.pyplot as plt
from cycler import cycler
c = plt.get_cmap('tab20c').colors
plt.rcParams['axes.prop_cycle'] = cycler(color=c)
This looks pretty dirty to me. Is there a better way?
Upvotes: 6
Views: 3693
Reputation: 339725
As said in the comments, it's not clear what "better" would mean. So I can think of two different ways in addition to the one from the question, which works perfectly fine.
Just to show a different way of setting the color cycler: Seaborn has a function set_palette
, which does essentially set the matplotlib color cycle. You could use it like
import matplotlib.pyplot as plt
import seaborn as sns
sns.set_palette("tab20c",plt.cm.tab20c.N )
If you want the cycler for each axes individually, you may use ax.set_prop_cycle
for an axes ax
.
import matplotlib.pyplot as plt
from cycler import cycler
fig, ax = plt.subplots()
ax.set_prop_cycle(cycler(color=plt.get_cmap('tab20c').colors))
Upvotes: 5