python反复运行清空plot图,Python:matplotlib-循环,清除并显示同一图上的不同图

在Python中,使用matplotlib可以通过两种方式实现类似MATLAB的循环更新同一图上的不同图。一是开启交互模式,利用`plt.ion()`,在每次循环中更新数据并调用`plt.pause()`。二是使用`FuncAnimation`模块简化创建动画的过程。这两个方法可以实现在一个图表上动态展示plot的变化。
摘要由CSDN通过智能技术生成

I want to see how a plot varies with different values using a loop. I want to see it on the same plot. But i do not want to remains of the previous plot in the figure. In MATLAB this is possible by creating a figure and just plotting over the same figure. Closing it when the loop ends.

Like,

fh = figure();

%for loop here

%do something with x and y

subplot(211), plot(x);

subplot(212), plot(y);

pause(1)

%loop done

close(fh);

I am not able to find the equivalent of this in matplotlib. Usually all the questions are related to plotting different series on the same plot, which seems to come naturally on matplotlib, by plotting several series using plt.plot() and then showing them all finally using plt.show(). But I want to refresh the plot.

解决方案

There are essentially two different ways to create animat

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值