简体   繁体   English

matplotlib。 如何在子图之间切换,而不是从头开始重新绘制?

[英]matplotlib. How do I switch between subplots, rather than replotting them from scratch?

I create a figure and fill it with a couple of subplots. 我创建了一个图形并用几个子图填充它。

As new data arrives, I'd like to draw it on a given subplot. 随着新数据的到来,我想在给定的子图上绘制它。

How do I switch between subplots so that I don't have to create new subplot objects each time? 如何在子图之间切换,这样我每次都不必创建新的子图对象?

Example: 例:

from matplotlib.pyplot import figure,

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

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

Assign subplot to a variable: 将子图分配给变量:

fig = matplotlib.pyplot.figure()

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

Then you can draw lines and points and whatever else you want with references to plt1 and plt2 然后你可以通过引用plt1plt2绘制线条和点以及你想要的任何其他plt2

Take a look at the reference for everything you can do with the plot. 看看你可以用情节做的所有事情的参考

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何告诉OSX使用brew中的matplotlib,而不是默认值? - How do I tell OSX to use matplotlib from brew, rather than default? 如何在matplotlib中创建具有不同wspace的子图? - How to create subplots with different wspace between them in matplotlib? 如何在 matplotlib 中合并子图? - How do I combine subplots in matplotlib? 如何使用matplotlib有选择地擦除2 y轴子图上的线。(Python) - How do I selectively erase lines on a 2 y-axis subplot using matplotlib.(Python) 如何使用 matplotlib 从 Pandas 数据框列中绘制具有不同标签的子图 - How do I plot subplots with different labels from pandas dataframe columns using matplotlib matplotlib中的plot_date和多列子图。 如何使用plot_date将1列更改为2列子图? - plot_date and multiple column subplots within matplotlib. How to change 1 column to 2 column subplot using plot_date? matplotlib - 如何将次要网格线的数量设置为 6 而不是 4? - matplotlib - how do I set number of minor grid lines to 6 rather than 4? 如何使用 matplotlib 为许多子图制作一个图例? - how do I make a single legend for many subplots with matplotlib? 如何绘制直方图的密度而非计数? (Matplotlib) - How do I plot my histogram for density rather than count? (Matplotlib) 我如何修改此代码,以免每次都重新绘制图形,matplotlib - How can I modify this code so that I am not replotting my graph everytime, matplotlib
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM