Matplotlib,一次设置多个参数?

时间:2014-04-30 20:29:21

标签: python graph parameters matplotlib default

有没有办法一次为多个图设置参数 - 基本上定义默认值?

我现在拥有的:

fig = plt.figure()
ax1 = fig.add_subplot(313)
ax1.scatter(entries,gvalues[0], color='b', marker = '1')
ax1.scatter(entries,gvalues[1], color = 'g', marker = 'v')
xticks([z for z in range(N)], namelist)
ylabel('Label1', ha='center', labelpad=28)
ylim(0,)
ax2 = fig.add_subplot(312, sharex=ax1)
ax2.scatter(entries,gvalues[2], color = 'b', marker = '1')
ax2.scatter(entries,gvalues[3], color= 'g', marker = 'v')
ylabel('Label2', ha='center', labelpad=28)
setp(ax2.get_xticklabels(),visible=False)
ylim(0,)

我将会有一些这些图表,如果我不必每次都设置ha = 'center', labelpad = 28ylim(0,),那就太棒了。

干杯

1 个答案:

答案 0 :(得分:1)

您可以使用词典存储您的选项,如下所示:

font_options = dict(ha='center', labelpad=28)

ax1.set_ylabel('Label1', **font_options)

...

ax2.set_ylabel('Label2', **font_options)

**font_options参数将解包字典中的每个键值对,并将其应用于ylabel函数。

对于ylim选项,您可以将限制存储在变量中,例如:

ylimit = 0

ylim(ylimit,)
相关问题