Disable the output of matplotlib pyplot

PythonMatplotlib

Python Problem Overview


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(A)

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

<matplotlib.lines.Line2D at 0xXXXXXXXX>

Can I disable this output?

Python Solutions


Solution 1 - Python

This output is what the plt function is returning (I presume here you meant to write plt.plot(A)). 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.

Solution 2 - Python

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);  

Solution 3 - Python

plt.show()

This way there is no need to create unnecessary variables.

E.g.:

import matplotlib.pyplot as plt

plt.plot(A)
plt.show()

Solution 4 - Python

use a semi-colon after the plot command

eg: plt.imshow(image,cmap);

will display the graph and stop the verbose

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionshelperView Question on Stackoverflow
Solution 1 - PythonChrisView Answer on Stackoverflow
Solution 2 - PythontacaswellView Answer on Stackoverflow
Solution 3 - PythonjoeDiHareView Answer on Stackoverflow
Solution 4 - Pythoncode-freezeView Answer on Stackoverflow