什么时候需要plt.show()显示一个图,什么时候不显示? [英] When is plt.show() required to show a plot and when is it not?
问题描述
由于下面的代码将显示一个没有 plt.show()
的图,那么 plt.show()
有什么意义?
Since the following code will show a plot without plt.show()
, what is the point of plt.show()
?
请告诉我何时需要 plt.show()
,因为这将使我更好地理解matplotlib的复杂性.
Please tell me when plt.show()
is required as this would allow me to appreciate the intricacy of matplotlib better.
注意:我在 Spyder (Anaconda) 中使用这个
N.B.: I'm using this in Spyder (Anaconda)
import matplotlib.pyplot as plt
plt.subplot(211) # the first subplot in the first figure
plt.plot([1, 2, 3])
推荐答案
根据脚本的位置要求还是不要求.
To require or not required depending on where your script is.
有 2 个上下文.
Matplotlib 用于终端或脚本,plt.show() 是必须的.
Matplotlib is used in a terminal or scripts, plt.show() is a must.
Matplotlib 用于 IPython shell 或笔记本(例如:Kaggle),不需要 plt.show().
Matplotlib is used in a IPython shell or a notebook (ex: Kaggle), plt.show() is unnecessary.
这篇关于什么时候需要plt.show()显示一个图,什么时候不显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!