7

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.

Cœur
39k25 gold badges206 silver badges281 bronze badges
asked Feb 7, 2015 at 17:08
2
  • Think we will need more info, show your code, imports and platform... Commented Feb 7, 2015 at 17:23
  • The error you described when using % matplotlib inline is due to an issue dealing with unicode and strings. Probably, you have characters encoded with latin-1 and a conversion is trying to use decode. However, decode is converting your character to unicode using the default encoding ascii and since that character is not found in ascii, the conversion fails. You should try to convert your string to unicode using decode ("\xe2".decode(encoding='latin-1')) before passing that data to matplotlib. Commented Feb 7, 2015 at 19:52

3 Answers 3

5

Change

ipython notebook --matplotlib=inline 

to

ipython notebook --matplotlib inline 

Notice no = sign.

answered Feb 7, 2015 at 19:10

Comments

3

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.

answered Feb 7, 2015 at 20:02

Comments

0

Thanks for all your helps. i've tried all of above, but did't work.

here i found that was bug in fontmanager.py in matplotlib 1.4.x, fixed with this development version of matplotlib and it worked.

i'm so sorry that i couldn't find it earlier. thanks for all of you.

answered Feb 8, 2015 at 7:00

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.