matplotlib: Creating two (stacked) subplots with SHARED X axis but SEPARATE Y axis values

前端 未结 3 764
时光取名叫无心
时光取名叫无心 2021-02-05 15:42

I am using matplotlib 1.2.x and Python 2.6.5 on Ubuntu 10.0.4. I am trying to create a SINGLE plot that consists of a top plot and a bottom plot.

The X axis is the date

3条回答
  •  死守一世寂寞
    2021-02-05 16:25

    You should change this line:

    ax = fig.add_subplot(111)
    

    to

    ax = fig.add_subplot(211)
    

    The original command means that there is one row and one column so it occupies the whole graph. So your second graph fig.add_subplot(212) cover the lower part of the first graph.

    Edit

    If you dont want the gap between two plots, use subplots_adjust() to change the size of the subplots margin.

提交回复
热议问题