How Do I Omit Matplotlib Printed Output In Python / Jupyter Notebook?
When I make a simple plot inside an IPython / Jupyter notebook, there is printed output, presumably generated from matplotlib standard output. For example, if I run the simple scri
Solution 1:
This output occurs since Jupyter automatically prints a representation of the last object in a cell. In this case there is indeed an object in the last line of input cell #1. That is the return value of the call to .set_title(...)
, which is an instance of type .Text
. This instance is returned to the global namespace of the notebook and is thus printed.
To avoid this behaviour, you can, as suggested in the comments, suppress the output by appending a semicolon to the end of the line, which works as of notebook v6.3.0
, jupyter_core v4.7.1
, and jupyterlab v3.0.14
:
axis.set_title('Histogram', size=20);
Another approach would assign the Text
to variable instead of returning it to the notebook. Thus,
my_text = axis.set_title('Histogram', size=20)
solves the problem as well.
Finally, put plt.show()
last.
...
axis.set_title('Histogram', size=20)
plt.show()
Post a Comment for "How Do I Omit Matplotlib Printed Output In Python / Jupyter Notebook?"