简体   繁体   English

Python matplotlib:显示后图形无法更新

[英]Python matplotlib: figure can not update after show

The following code works fine:以下代码工作正常:

Python 3.8.2 (default, Apr  8 2020, 14:31:25) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib.pyplot as plt
>>> fig = plt.figure()
>>> fig.suptitle("Empty figure")
Text(0.5, 0.98, 'Empty figure')
>>> fig.show()

But if I set subtitle (or do any other thing) after show , it will not work, even I run show() again.但是,如果我在show之后设置字幕(或做任何其他事情),即使我再次运行show() ,它也不起作用。

Python 3.8.2 (default, Apr  8 2020, 14:31:25) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib.pyplot as plt
>>> fig = plt.figure()
>>> fig.show()
>>> fig.suptitle("Empty figure")
Text(0.5, 0.98, 'Empty figure')
>>> fig.show()

I am new to python.我是 python 的新手。 Could anyone please help me?有人可以帮我吗?

In matplotlib, the .show() method by nature is designed to block any further execution of code after it is called until the shown figure is closed.在 matplotlib 中, .show()方法本质上旨在阻止代码在调用后的任何进一步执行,直到所示图关闭。 Unless you turn on an interactive mode by calling .ion() before calling .show() , or there is an optional boolean parameter to be passed in to turn the blocking feature off as well:除非您在调用.ion() .show()交互模式,否则还有一个可选的 boolean 参数要传入以关闭阻塞功能:

plt.show(block=False)

Check out the documentation here: https://matplotlib.org/3.2.1/api/_as_gen/matplotlib.pyplot.show.html在此处查看文档: https://matplotlib.org/3.2.1/api/_as_gen/matplotlib.pyplot.show.html

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM