How do I omit Matplotlib printed output in Python / Jupyter notebook?


To omit matplotlib printed output in Python/Jupeter notebook, we can take the following steps −

  • import numpy as np.
  • from matplotlib import pyplot as plt
  • Create points for x, i.e., np.linspace(1, 10, 1000)
  • Now, plot the line using plot() method.
  • To hide the instance, use plt.plot(x); (with semi-colon)
  • Or, use _ = plt.plot(x).

Example

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]:

Output

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

Updated on: 15-Jun-2021

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements