简体   繁体   English

在matplotlib中为绘图设置临时默认值

[英]Setting temporary defaults for plots in matplotlib

If I'm making a series of plots such as: 如果我要进行一系列绘图,例如:

fig,axes = plt.subplots(1,3,figsize=(20,5))

#First Batch of plots
axes[0].hist(...)
axes[1].hist(...)
axes[2].hist(...)

#Second Batch of plots
axes[0].hist(...)
axes[1].hist(...)
axes[2].hist(...)

#Third Batch of plots
axes[0].hist(...)
axes[1].hist(...)
axes[2].hist(...)


plt.show()

and I want all the plots in a single batch to have the same style (eg the same label, the same color,...) I can manually go and add these to the .hist command, but is there a way to set a 'temporary default' that will make the style of each batch of plots the same? 我希望同一批中的所有图都具有相同的样式(例如,相同的标签,相同的颜色,...),我可以手动将其添加到.hist命令中,但是有一种方法可以设置“临时默认”将使每批地块的样式相同吗?

One way to do it is to define a dict with the arguments and pass it to each call: 一种方法是用参数定义一个字典并将其传递给每个调用:

kwargs = dict(lw=3, c='C2', ls='--')

plt.figure()

plt.subplot(1, 2, 1)
plt.plot([0, 1], **kwargs)

plt.subplot(1, 2, 2)
plt.plot([1, 0], **kwargs)

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM