I can set a default color cycle for lines in matplotlib using matplotlib.rcParams['axes.color_cycle'] = my_color_list
, but I can't figure out how to do the same thing with line styles (i.e. '-','--','-.',':'
). I know I can set this using something like
linecycler = itertools.cycle(lines)
for i in range(n):
plt.plot(x[i],y[i],next(linecycler))
but I'd like to be able to do something more like the color cycle thing so I don't have to make a new cycler every time I want to plot. How can I do this?
If you're running matplotlib 1.5 or greater, then you can introduce cyclers for all plot properties in rcParam
using axes.prop_cycle
(and axes.color_cycle
was deprecated in favor of axes.prop_cycle
). In short, you should be able to do something along these lines:
import matplotlib.pyplot as plt
from cycler import cycler
plt.rc('axes', prop_cycle=(cycler('color', ['r', 'g', 'b', 'y']) +
cycler('linestyle', ['-', '--', ':', '-.'])))
See this example and the docs for details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With