How do I get multiple subplots in matplotlib?

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

    read the documentation: matplotlib.pyplot.subplots

    pyplot.subplots() returns a tuple fig, ax which is unpacked in two variables using the notation

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

    the code

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

    does not work because subplots()is a function in pyplot not a member of the object Figure.

提交回复
热议问题