Plotting grids across the subplots Python matplotlib

前端 未结 2 1102
情歌与酒
情歌与酒 2021-02-13 22:22

I have tried the following:

d = [1,2,3,4,5,6,7,8,9]
f = [0,1,0,0,1,0,1,1,0]
fig = plt.figure()
fig.set_size_inches(30,10)
ax1 = fig.add_subplot(211)
line1 = ax         


        
2条回答
  •  醉话见心
    2021-02-13 23:24

    Here is my solution:

    import matplotlib.pyplot as plt
    
    x1 = [1,2,3,4,5,6,7,8,9]
    x2= [0,1,0,0,1,0,1,1,0]
    x3= range(-10,0)
    # frameon=False removes frames
    # fig, (ax1,ax2, ax3) = plt.subplots(nrows=3, sharex=True, subplot_kw=dict(frameon=False))
    fig, (ax1,ax2, ax3) = plt.subplots(nrows=3, sharex=True)
    # remove vertical gap between subplots
    plt.subplots_adjust(hspace=.0)
    
    ax1.grid()
    ax2.grid()
    ax3.grid()
    
    ax1.plot(x1)
    ax2.plot(x2)
    ax3.plot(x3)
    

    Without frames subplot_kw=dict(frameon=False):

提交回复
热议问题