Skip to main content
 首页 » 编程设计

python之什么时候需要 plt.show() 来显示情节,什么时候不需要

2024年12月31日7shanyou

由于以下代码将显示没有plt.show() 的情节,plt.show() 的意义何在?

请告诉我何时需要 plt.show(),因为这会让我更好地理解 matplotlib 的复杂性。

注意:我在 Spyder (Anaconda) 中使用它

import matplotlib.pyplot as plt 
plt.subplot(211)             # the first subplot in the first figure 
plt.plot([1, 2, 3]) 

请您参考如下方法:

是否需要取决于您的脚本所在的位置。

有 2 个上下文。

  1. 在终端或脚本中使用 Matplotlib,plt.show() 是必须的。

  2. Matplotlib 用于 IPython shell 或笔记本(例如:Kaggle),不需要 plt.show()。