如何在 Python / Jupyter notebook 中忽略 Matplotlib 列印輸出?


要在 Python/Jupyter notebook 中忽略 matplotlib 列印輸出,我們可以採取以下步驟 -

  • 匯入 numpy
  • matplotlib 匯入 pyplot
  • 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]: [<matplotlib.lines.Line2D at 0x7faa3852fac8>]

In [5]: plt.plot(x);

In [6]: _ = plt.plot(x)

In [7]:

輸出

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

更新日期: 15-6-2021

2K+ 次瀏覽

開啟你的 職業之旅

透過完成課程獲得認證

立即開始
廣告
© . All rights reserved.