How do I get multiple subplots in matplotlib?

后端 未结 6 978
自闭症患者
自闭症患者 2020-11-22 06:49

I am a little confused about how this code works:

fig, axes = plt.subplots(nrows=2, ncols=2)
plt.show()

How does the fig, axes work in this

6条回答
  •  遥遥无期
    2020-11-22 07:01

    import matplotlib.pyplot as plt
    
    fig, ax = plt.subplots(2, 2)
    
    ax[0, 0].plot(range(10), 'r') #row=0, col=0
    ax[1, 0].plot(range(10), 'b') #row=1, col=0
    ax[0, 1].plot(range(10), 'g') #row=0, col=1
    ax[1, 1].plot(range(10), 'k') #row=1, col=1
    plt.show()
    

提交回复
热议问题