首页 > 解决方案 > 将 AxesSubplots 的 pyplot 数组耦合到图形对象

问题描述

我有一个 pandas DataFrame,我正在使用 df.plot 函数来制作一个子图面板。

像这样的东西:

x = np.random.randn(50)
df = pd.DataFrame({'1': x, '2': x, '3': x, '4':x})

ax_lst = df.plot(subplots = True, layout = (2,2))

df.plot 函数返回一个 AxesSubplots 的 numpy 数组。如何将它与图形对象耦合,以便更改图形级属性?

我已经尝试过,但没有奏效:

fig = plt.figure()
fig.axes.append(ax_lst)

标签: pythonpandasmatplotlib

解决方案


每个Axes对象都有一个get_figure方法。在你的情况下,

fig = ax_lst[0].get_figure()

推荐阅读