Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pandas plot doesn't show in ipython notebook as inline

I'm trying to plot graph in ipython notebook inline, but .plot() methos just shows the object information, as

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

but no graph. also i could make it show graph with plt.show(), but i want do it inline. so i tryed %matplotlib inline and ipython notebook --matplotlib=inline, but it was no helpful.

If i use %matplotlib inline, then .plot() shows

/Users/<username>/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/IPython/core/formatters.py:239: 
FormatterWarning: Exception in image/png formatter: 'ascii' codec can't decode byte 0xe2 in position 0: ordinal not in range(128) FormatterWarning,

and using ipython notebook --matplotlib=inline shows same.

like image 618
HMPark Avatar asked Feb 07 '15 17:02

HMPark


2 Answers

Change

ipython notebook --matplotlib=inline 

to

ipython notebook --matplotlib inline 

Notice no = sign.

like image 176
alacy Avatar answered Oct 06 '22 00:10

alacy


I will give you an example based on my comment above:

You have something like this:

import matplotlib.pyplot as plt

%matplotlib inline

legend = "\xe2"

plt.plot(range(5), range(5))
plt.legend([legend])

which results in:

UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 0: ordinal not in range(128)

As I said, this is because matplotlib wants to use strings of type unicode. So, in the process of plotting, matplotlib tries to decode your string to convert it to unicode using decode. However, decode has ascii as default encoding, and since your character doesn't belong to ascii, an error is shown. The solution is to decode the string yourself with the appropriate encoding:

import matplotlib.pyplot as plt

%matplotlib inline

legend = "\xe2".decode(encoding='latin-1')

plt.plot(range(5), range(5))
plt.legend([legend])

enter image description here

By the way, regarding the use ipython notebook --matplotlib inline, it is considered bad practice to do that because you are hiding what you did in order to obtain the resulting notebook. It is much better to include %matplotlib inline in your notebook.

like image 21
Robert Smith Avatar answered Oct 06 '22 00:10

Robert Smith