Python Matplotlib,一次设置多个参数?
有没有一种方法可以一次为多个图形设置参数——基本上是定义一个默认值 我现在所拥有的:Python Matplotlib,一次设置多个参数?,python,graph,parameters,matplotlib,default,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) ylabe
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=28
和ylim(0,)
,那就太好了
干杯您可以使用字典存储选项,如下所示:
font_options = dict(ha='center', labelpad=28)
ax1.set_ylabel('Label1', **font_options)
...
ax2.set_ylabel('Label2', **font_options)
**font\u options
参数将解压字典中的每个键值对,并在ylabel
函数中应用它们
类似地,对于ylim
选项,您可以将限制存储在变量中,例如:
ylimit = 0
ylim(ylimit,)