How do I get multiple subplots in matplotlib?

后端 未结 6 1000
自闭症患者
自闭症患者 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:09

    You might be interested in the fact that as of matplotlib version 2.1 the second code from the question works fine as well.

    From the change log:

    Figure class now has subplots method The Figure class now has a subplots() method which behaves the same as pyplot.subplots() but on an existing figure.

    Example:

    import matplotlib.pyplot as plt
    
    fig = plt.figure()
    axes = fig.subplots(nrows=2, ncols=2)
    
    plt.show()
    

提交回复
热议问题