Reputation: 547
I have to plot different curves in one matplotlib figure. Each curve must have its own style (color, thickness, etc..) and I would like to set the styles in one matplotlibrc file. I would like to use a name like line1, line2, etc.. to refer to different styles, and not to a color cycle. Is this possible in motplotlib?
Upvotes: 2
Views: 265
Reputation: 3340
cycler()
can be used to set cycles for linewidth
, linestyle
, etc. as well as color
. The length of the list of each argument must be the same. The list of available properties is defined here.
# series 1: color=red, linewidth=1, linestyle='-'
# series 2: color=blue, linewidth=2, linestyle='--'
axes.prop_cycle: cycler(color=['red', 'blue'], linewidth=[1, 2], linestyle=['-', '--'])
Upvotes: 0
Reputation: 339560
The matplotlib rc file is meant to provide the default style for a plot, its not meant to provide styles in the way of Cascading Style Sheets (CSS) or classes.
So what is possible, is to create several rc files and use them in a context, as explained in the temporary-styling part of the customizing tutorial, e.g. using a file called line1.mplstyle
you could do
with plt.style.context(('line1')):
plt.plot([1,2,3])
Because this seems to be a little overkill for just setting some line properties, it might be sufficient to simply create some argument dictionaries to provide to the plot command, like so:
line1 = dict(lw=2, ls=":", color="red")
line2 = dict(lw=0.8, ls="-", color="blue")
ax.plot([1,2,3], **line1)
ax.plot([1,2,3], **line2)
Upvotes: 1