64

I have an array A of shape (1000, 2000). I use matplotlib.pyplot to plot the array, which means 1000 curves, using

import matplotlib.pyplot as plt

plt.plot(A)

The figure is fine but there are a thousand lines of:

<matplotlib.lines.Line2D at 0xXXXXXXXX>

Can I disable this output?

0

4 Answers 4

71

You can also suppress the output by use of ; at the end (assuming you are doing this in some sort of interactive environment)

 plot(A);  
Sign up to request clarification or add additional context in comments.

Comments

65

matplotlib.pyplot.plot returns a list of Line2D objects. To suppress this output, assign the return object a name:

_ = plt.plot(A)

_ is often used to indicate a temporary object which is not going to be used later on. Note that this output you are seeing will only appear in the interpreter, and not when you run the script from outside the interpreter.

Other methods return objects, which may be printed, can also be suppressed by assigning them with _ = ....

Comments

31

plt.show()

This way there is no need to create unnecessary variables.

E.g.:

import matplotlib.pyplot as plt

plt.plot(A)
plt.show()

Comments

-1

To ignore warnings

import warnings warnings.filterwarnings("ignore")

This will resolve your issue.

2 Comments

This does not work. The inline will still output.
This has nothing to do with the question. <matplotlib.lines.Line2D at 0xXXXXXXXX> is an object Returned by plt.plot, it is not a warning, and this will do nothing for the issue.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.