How can I plot separate Pandas DataFrames as subplots?

后端 未结 9 2144
离开以前
离开以前 2020-11-22 17:00

I have a few Pandas DataFrames sharing the same value scale, but having different columns and indices. When invoking df.plot(), I get separate plot images. what

9条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-22 17:36

    You can use the familiar Matplotlib style calling a figure and subplot, but you simply need to specify the current axis using plt.gca(). An example:

    plt.figure(1)
    plt.subplot(2,2,1)
    df.A.plot() #no need to specify for first axis
    plt.subplot(2,2,2)
    df.B.plot(ax=plt.gca())
    plt.subplot(2,2,3)
    df.C.plot(ax=plt.gca())
    

    etc...

提交回复
热议问题