matplotlib中的plt.draw()和plt.show()之间的区别 [英] Difference between plt.draw() and plt.show() in matplotlib

查看:152
本文介绍了matplotlib中的plt.draw()和plt.show()之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道为什么有些人在 plt.show() 之前将 plt.draw() 放入他们的代码中.对于我的代码,plt.draw() 的行为似乎没有改变任何关于输出的内容.我在互联网上进行了搜索,但找不到任何有用的信息.

I was wondering why some people put a plt.draw() into their code before the plt.show(). For my code, the behavior of the plt.draw() didn't seem to change anything about the output. I did a search on the internet but couldn't find anything useful.

(假设我们将 pyplot 导入为 from matplotlib import pyplot as plt)

(assuming we imported pyplot as from matplotlib import pyplot as plt)

推荐答案

plt.show() 将显示您正在处理的当前图形.

plt.show() will display the current figure that you are working on.

plt.draw() 将重新绘制图形.这允许您在交互模式下工作,并且如果您更改了数据或格式,则允许图表本身更改.

plt.draw() will re-draw the figure. This allows you to work in interactive mode and, should you have changed your data or formatting, allow the graph itself to change.

plt.draw 文档状态:

在交互模式下使用它来更新已使用一个或多个绘图对象方法调用更改的图形.如果完全通过pyplot函数完成图形修改,一系列修改以pyplot函数结尾,或者matplotlib处于非交互模式且修改序列以show()或savefig()结尾,则不需要此方法./p>

This is used in interactive mode to update a figure that has been altered using one or more plot object method calls; it is not needed if figure modification is done entirely with pyplot functions, if a sequence of modifications ends with a pyplot function, or if matplotlib is in non-interactive mode and the sequence of modifications ends with show() or savefig().

这似乎表明在不处于交互模式时在 plt.show() 之前使用 plt.draw() 在绝大多数情况下是多余的.唯一可能需要的是,如果您进行了一些非常奇怪的修改,而这些修改不涉及使用pyplot函数.

This seems to suggest that using plt.draw() before plt.show() when not in interactive mode will be redundant the vast majority of the time. The only time you may need it is if you are doing some very strange modifications that don't involve using pyplot functions.

请参阅Matplotlib文档,"交互式数字"了解更多信息.

Refer to the Matplotlib doc, "Interactive figures" for more information.

这篇关于matplotlib中的plt.draw()和plt.show()之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆