Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Matplotlib,一次设置多个参数?_Python_Graph_Parameters_Matplotlib_Default - Fatal编程技术网

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