在Matplotlib中,该参数在fig.add_subplot(111)中是什么意思?

问题描述 投票:463回答:7

有时我遇到这样的代码:

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()的参数是什么意思?

有时我遇到这样的代码:import matplotlib.pyplot as plt x = [1、2、3、4、5] y = [1、4、9、16、25]图= plt.figure() fig.add_subplot(111)plt.scatter(x,y)plt.show()其中...

python matplotlib figure
7个回答
460
投票

这些是编码为单个整数的子图网格参数。例如,“ 111”表示“ 1x1网格,第一个子图”,“ 234”表示“ 2x3网格,第4个子图”。


503
投票

我认为最好用下图来解释:


38
投票

Constantin的答案很明显,但是从更多的背景来看,此行为是从Matlab继承的。


19
投票

我的解决方法是


15
投票

enter image description here


9
投票

fig.add_subplot(ROW,COLUMN,POSITION)


0
投票

add_subplot()

© www.soinside.com 2019 - 2024. All rights reserved.