matplotlib - jupyter & matplotlib - 如何打开和关闭图形上的交互模式
问题描述
问题
在 Jupyter notebook 中,是否可以关闭图形上的交互模式?ax.plot()
从命令行 python 运行时不显示一行,但在 Jupyter 笔记本单元格中,它显示了。
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(7,5))
plt.ioff()
ax.plot([1.6, 2.7]) # <--- Still the line shows up in a jupyter notebook
...
plt.ion()
plt.draw()
plt.show()
版本
$ jupyter notebook --version
6.2.0
from platform import python_version
print(python_version())
3.8.8
有关的
matplotlib python inline on/off建议使用%matplotlib
但不知道为什么使用魔法命令来打开/关闭交互模式。
它还在下面提到,但不确定它的确切含义。
on 和 ioff 设置交互模式,确定是否在每个绘图命令后更新绘图(交互模式打开)或等待 plt.show()(如果交互模式关闭)。这独立于内联,它决定笔记本或控制台是否应该显示图形(这会在绘图更新时发生,这意味着如果使用 ion 设置交互模式,则在每个绘图命令中,或者如果使用 ioff 未设置,则在 plt.plot 之后)。
解决方案
推荐阅读
- reactjs - fontFamily 不是系统字体,没有通过 Font.loadAsync 加载,而是通过 Font.loadAsync
- c# - How do I increase speed every time I kill an enemy?
- firebase - Firestore POST 请求失败(Arduino WifiESP)
- deep-learning - 为什么向变分编码器的解码器添加一层 transpose_convolution 会导致形状与原始形状不相似?
- javascript - 在 Netlify 上部署站点时,使用 vanilla javascript 的会话超时无法正常工作
- c# - 军事格式的日期时间
- clojure - 如何避免 Clojure 互操作中的“非法反射访问”警告。(投掷?)
- android - Android 试图从公钥字节数组中获取公钥:java.lang.IllegalArgumentException: Invalid point encoding 0x30
- java - 引起:org.springframework.beans.FatalBeanException:检测到依赖循环
- git - 用分支上的第一个提交压缩合并提交