matplotlib 如何在子图之间切换,而不是重新绘制它们?

2024-06-07 14:31:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我创建一个图形并用几个子块填充它。

当新数据到达时,我想在给定的子块上绘制它。

如何在子块之间切换,以便每次都不必创建新的子块对象?

示例:

from matplotlib.pyplot import figure,

figure()
subplot(2,1,1)
subplot(2,1,2)

# now go back and plot something on subplot 1 ...?

Tags: 数据对象fromimport图形go示例matplotlib
1条回答
网友
1楼 · 发布于 2024-06-07 14:31:30

将子批次分配给变量:

fig = matplotlib.pyplot.figure()

plt1 = fig.add_subplot(2,1,1)
plt2 = fig.add_subplot(2,1,2)

然后您可以使用对plt1plt2的引用来绘制线和点以及其他任何需要的内容

看看reference中的所有内容,你可以用这个情节来做。

相关问题 更多 >

    热门问题