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

Python 在matplotlib中设置绘图的临时默认值,python,matplotlib,Python,Matplotlib,如果我正在制作一系列绘图,例如: 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].his

如果我正在制作一系列绘图,例如:

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()

我希望单个批次中的所有绘图具有相同的样式(例如,相同的标签、相同的颜色……),我可以手动将它们添加到
.hist
命令,但是有没有一种方法可以设置“临时默认值”,使每批绘图的样式相同?

一种方法是使用参数定义dict并将其传递给每个调用:

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)

如果您的意思是在每次调用
hist
时都有很多重复的关键字,您可以事先定义一个关键字的dict,比如
my_style=dict(…)
,然后将该dict作为
ax.hist(…,**my_style)
传递给
hist
调用。