python - 什么时候需要 plt.show() 来显示绘图,什么时候不需要?
问题描述
由于下面的代码将显示一个没有 的情节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个上下文。
Matplotlib 用于终端或脚本中,plt.show() 是必须的。
Matplotlib 用于 IPython shell 或笔记本(例如:Kaggle),不需要 plt.show()。
推荐阅读
- r - 如何使用正则表达式匹配 R 中使用 gsub 的第三个正斜杠?
- python - 字符串文字中的正斜杠行为异常
- javascript - 套接字 io 中的回调未按预期工作
- c# - cancelTOken 和同步 sql 调用的计时问题
- api - 从代码调用时,获取 Swagger API 响应错误 StatusCode 404
- c - 在 ARM Cortex-M 系列上确定函数的返回地址
- java - 我在 WebSphere 应用程序服务器上初始化 SparkContext 时遇到 SparkContext 错误
- machine-learning - 如何为我的机器学习问题建模?
- sql - SQL - 在没有游标或 sp_foreach 的情况下删除实例上所有数据库上的用户
- core-data - SwiftUI - 将 fetchResult 传递给另一个视图