matplotlib的plt.ion()没用/不能交互

https://blog.csdn.net/yzy__zju/article/details/85008603
这个链接的方法反复试过了,plt.ioff()就是无法达到图片显示的效果,后来发现只要输入plt.ion() 就不能显示图片, 输入plt.ioff() 关闭交互模式就可以显示图片了,但是程序恢复阻塞。
不排除是新版本问题:

hellopython@ubuntu:~$ pip freeze
matplotlib==3.1.2

http://www.voidcn.com/article/p-fdmzbqxj-btq.html
该链接给我启示,通过 plt.pause(0.1-0.000001)来让它暂停不消失,从而显示图片又能交互。程序如下:

Python 3.6.9 (default, Nov  7 2019, 10:44:02) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib.pyplot as plt
>>> plt.ion()
>>> plt.plot([1,2,3],[3,6,4])
[<matplotlib.lines.Line2D object at 0x7f3741718710>]
>>> plt.pause(0.0001)
>>> ax = plt.gca()
>>> ax.lines
[<matplotlib.lines.Line2D object at 0x7f3741718710>]
>>> ax.lines[0].set_color('g')
>>> plt.pause(1)
>>> plt.plot([2,2,5],[3,5,8])
[<matplotlib.lines.Line2D object at 0x7f3764588668>]
>>> plt.pause(0.0001)
>>> ax.lines[1].set_color('y')
>>> plt.pause(0.1)
>>> plt.plot([2,3,5],[3,3,6])
[<matplotlib.lines.Line2D object at 0x7f37417423c8>]
>>> ax.lines[2].set_color('r')
>>> plt.pause(10)

result as follow:
在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值