Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to remove matplotlib output lines from showing in jupyter notebook when plotting [duplicate]

for example, when I plot something and add titles and so forth, I get a list of lines showing output like the ones below before the actual plot shows, sometimes very long lists.

<matplotlib.figure.Figure at 0x244deb8dd68>

<matplotlib.axes._subplots.AxesSubplot at 0x244deb99358>

<matplotlib.text.Text at 0x244defc9240>

Is there a way to hide these when plotting?

like image 922
Ricky Avatar asked Mar 06 '17 21:03

Ricky


People also ask

How do you remove the output from a Jupyter notebook?

Press 'control-shift-p', that opens the command palette. Then type 'clear cell output'. That will let you select the command to clear the output.

How do I make lines disappear in matplotlib?

To hide lines in Matplotlib, we can use line. remove() method.

What is %% capture in Jupyter?

What does %% capture do in Jupyter? Capturing Output With %%capture IPython has a cell magic, %%capture , which captures the stdout/stderr of a cell. With this magic you can discard these streams or store them in a variable. By default, %%capture discards these streams. This is a simple way to suppress unwanted output.

What happens if I dont use %Matplotlib inline?

It just means that any graph which we are creating as a part of our code will appear in the same notebook and not in separate window which would happen if we have not used this magic statement.


1 Answers

Add ";" after your matplotlib commands. This seems to suppress output.

plt.plot(np.arange(0,5))
plt.title('Some Title')

Yields:

<matplotlib.text.Text at 0x119188490>

and an image.

Yet:

plt.plot(np.arange(0,5))
plt.title('Some Title');

just yields the image.

This was done using python 2 in a v4 Jupyter notebook.

like image 116
TheoBarnhart Avatar answered Sep 30 '22 03:09

TheoBarnhart