Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide matplotlib descriptions in jupyter notebook [duplicate]

I am not sure what is the correct term for this, but here is what I see when I plot something:

enter image description here

The plots is actually what I want so see, but jupyter notebook also outputs some text: <matplotlib.axes._subplots.AxesSubplot at 0x1263354d0>, <matplotlib.figure.Figure at 0x1263353d0> which I am trying to get rid of.

After some searching, the only thing I was able to find is plt.ioff(), which didn't help me. Is there a way to get rid of the text?

like image 468
Salvador Dali Avatar asked Aug 16 '16 06:08

Salvador Dali


People also ask

What does %Matplotlib do in Jupyter?

In the IPython notebook, you also have the option of embedding graphics directly in the notebook, with two possible options: %matplotlib notebook will lead to interactive plots embedded within the notebook. %matplotlib inline will lead to static images of your plot embedded in the notebook.

What happens if I dont use %Matplotlib inline?

In the current versions of the IPython notebook and jupyter notebook, it is not necessary to use the %matplotlib inline function. As, whether you call matplotlib. pyplot. show() function or not, the graph output will be displayed in any case.


2 Answers

You can finish the corresponding (matplotlib) line with a semicolon ;

like image 107
Luis Avatar answered Sep 21 '22 05:09

Luis


This is a bit of a workaround, but it should work consistently:

1. Assign the plotting function to a variable (which could also be useful if you need to access some plot elements later on)

plt.figure(figsize=(3, 3))  plot = plt.plot(range(10),                 [x*x for x in range(10)],                 'o-') 

2. Add a "pass" at the bottom of the cell (or an equivalent operation with no consequence)

plt.figure(figsize=(3, 3))  plt.plot(range(10),          [x*x for x in range(10)],          'o-') pass 

3. Add a semicolon at the end of the last statement

plt.figure(figsize=(3, 3))  plt.plot(range(10),          [x*x for x in range(10)],          'o-'); 
like image 45
mgalardini Avatar answered Sep 19 '22 05:09

mgalardini