如何在IPython notebook 中隐藏?


要在调用 plot() 方式时隐藏 matplotlib.lines.Line2D 实例,我们可以执行以下步骤:

  • 将 numpy 导入为 np

  • matplotlib 中导入 pyplot 为 plt

  • 为 x 创建点,即 np.linspace(1, 10, 1000)

  • 现在使用 plot() 方法绘制线。

  • 若要隐藏实例,请使用 plt.plot(x);(带分号)

  • 或者,使用 _ = plt.plot(x)

示例

In [1]: import numpy as np
In [2]: from matplotlib import pyplot as plt
In [3]: x = np.linspace(1, 10, 1000)
In [4]: plt.plot(x)
Out[4]: []
In [5]: plt.plot(x);
In [6]: _ = plt.plot(x)
In [7]:

输出

Out[4]: [<matplotlib.lines.Line2D at 0x7faa3852fac8>]

更新日期: 2021 年 4 月 9 日

342 次浏览

开启你的 职业

通过完成课程获得认证

开始
广告
© . All rights reserved.