通过编程方式停止 Jupyter notebook 中特定图像的交互


若要通过编程方式停止 Jupyter notebook 中特定图像的交互,我们可以在此之后使用 plt.off() 停止任何交互。

按顺序执行以下命令 −

  • %matplotlib auto
  • import matplotlib.pyplot as plt
  • plt.rcParams["figure.figsize"] = [7.50, 3.50]
  • plt.rcParams["figure.autolayout"] = True
  • 创建一个图像和一组子图。
  • 在轴上绘制直线(从第 5 步开始)。
  • 关闭交互。
  • 若要显示该图像,请使用 show() 方法。

示例

In [1]: %matplotlib auto
Using matplotlib backend: Qt5Agg

In [2]: import matplotlib.pyplot as plt

In [3]: plt.rcParams["figure.figsize"] = [7.50, 3.50]
   ...: plt.rcParams["figure.autolayout"] = True

In [4]: fig, ax = plt.subplots()

In [5]: ax.plot([2, 4, 7, 5, 4, 1])
Out[5]: [<matplotlib.lines.Line2D at 0x7fa6e00f5e48>]

In [6]: plt.ioff()
In [7]: ax.plot([1, 1, 2, 1, 2, 2])
Out[7]: [<matplotlib.lines.Line2D at 0x7fa6e0063ef0>]

In [8]: fig.show()

In [9]:

输出

更新于: 08-Jul-2021

633 次浏览

职业生涯开局

完成课程后获得认证

开始
广告
© . All rights reserved.