Python-在Matplotlib中,该参数在fig.add_subplot(111)中意味着什么?
有时我遇到这样的代码:
import matplotlib.pyplot as plt
x = [1, 2, 3, 4, 5]
y = [1, 4, 9, 16, 25]
fig = plt.figure()
fig.add_subplot(111)
plt.scatter(x, y)
plt.show()
产生:
我一直在疯狂地阅读文档,但是找不到关于的解释111
。有时我看到一个212
。
论据fig.add_subplot()
是什么意思?
-
这些是编码为单个整数的子图网格参数。例如,
“ 111”
表示“1x1
网格,第一个子图”,而“234
”表示“2x3
网格,第4个子图”。的替代形式
add_subplot(111)
是add_subplot(1, 1, 1)
。 -
我认为最好用以下图片解释:
要初始化以上内容,请输入:
import matplotlib.pyplot as plt fig = plt.figure() fig.add_subplot(221) #top left fig.add_subplot(222) #top right fig.add_subplot(223) #bottom left fig.add_subplot(224) #bottom right plt.show()