Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.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
matplotlib获取给定地物包含的所有轴以应用某些设置_Matplotlib_Axes - Fatal编程技术网

matplotlib获取给定地物包含的所有轴以应用某些设置

matplotlib获取给定地物包含的所有轴以应用某些设置,matplotlib,axes,Matplotlib,Axes,我正在编写一个函数,用于修改图形上的轴大小和位置,但当出现双轴时,会出现问题: import matplotlib.pyplot as plt def fig_layout(fig, vspace = 0.3): # function to make space at the bottom for legend box and #+ other text input for ax in ~~~fig.axes~

我正在编写一个函数,用于修改图形上的轴大小和位置,但当出现双轴时,会出现问题:

import matplotlib.pyplot as plt

def fig_layout(fig, vspace = 0.3):  #  function to make space at the bottom for legend box and
                                    #+ other text input
    for ax in ~~~fig.axes~~~: #  Here 'fig.axes' is not right, I need to find the exact syntax
                              #+ I need to put
        box = ax.get_position()
        ax.set_position([box.x0, box.y0 + box.height * vspace,
        box.width, box.height * (1 - vspace)])

x = np.arange(10)
fig = plt.figure()
ax1 = fig.add_subplot(1, 1, 1)
n = 3
line = {}
for i in range(3):
    line['lines'].append(ax1.plot(x, i*x**2))
    line['labels'].append(r'$y = %i \cdot x^2$'%i)
ax1.set_title('example plot')

ax2 = ax1.twinx()
line['lines'].append(ax2.plot(x, x^-1, label = r'$y = x^-1$'))
line['labels'].append(r'$y = x^-1$')
leg = ax1.legend(line['lines'], line['labels'])
fig_layout(fig)
#  I will put the legend box at the bottom of the axes with another function.
plt.show()
我想你可以用

例如,要修改第一个子图的标题,可以执行以下操作:

plt.gcf().get_axes()[0].set_title("example plot")