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: