Matplotlib:从要插入到新子图中的函数返回的轴

Matplotlib: returned AXes from functions to be inserted into new subplots

所以我有这两个函数来绘制时间序列和直方图。

ax1 = plotTimeSeries(df=dfDelay_Vector)
ax2 = plotHistogram( df=dfDelay_Hist)

每个 return 一个 ax 对象,它们都产生一个情节。到目前为止,还不错。

现在,我有了一个新功能,它会尝试将这些情节引入子情节。 axes 是一个列表,例如 axes = [ax1,ax2]

def drawSubPlots(rows, cols, axes):
    fig, ax = plt.subplots(rows, cols)
    for i in range(len(axes)):
        ax[i] = axes[i]

...但我得到的只是一个空的数字。

如何将 return 轴插入新的子图中?

谢谢!

所以,按照上面的人的建议,我得出了以下结论:

fig, ax = drawSubPlots(2,1)
ax1     = plotTimeSeries(df=dfDelay_Vector, ax=ax[0] )
ax2     = plotHistogram( df=dfDelay_Hist,   ax=ax[1] ) 

这样做,会产生下一个子图:

仍然需要自己调整图(xtickslabels 的方向、字体大小、子图中系列的颜色、直方图中条形的大小),但主要内容已涵盖!

谢谢!