How to set default Matplotlib axis colour cycle -
the default axis colour cycle in matplotlib 2.0 called tab10
:
i want use different qualitative colour cycle, such tab20c
:
i have used code change default axis colour cycle:
import matplotlib.pyplot plt cycler import cycler c = plt.get_cmap('tab20c').colors plt.rcparams['axes.prop_cycle'] = cycler(color=c)
this looks pretty dirty me. there better way?
as said in comments, it's not clear "better" mean. can think of 2 different ways in addition 1 question, works fine.
(a) use seaborn
just show different way of setting color cycler: seaborn has function set_palette
, set matplotlib color cycle. use like
import matplotlib.pyplot plt import seaborn sns sns.set_palette("tab20c",plt.cm.tab20c.n )
(b) set cycler axes only
if want cycler each axes individually, may use ax.set_prop_cycle
axes ax
.
import matplotlib.pyplot plt cycler import cycler fig, ax = plt.subplots() ax.set_prop_cycle(cycler(color=plt.get_cmap('tab20c').colors))
Comments
Post a Comment