2015-02-07 57 views
6

我想在IPython的笔记本内嵌绘制图形,但.plot() methos只是显示对象的信息,大熊猫情节不IPython的笔记本电脑显示为在线

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

,但没有图形。我也可以使它与plt.show()显示图形,但我想要它内联。所以我尝试了%matplotlib inlineipython notebook --matplotlib=inline,但它没有帮助。

如果我使用%matplotlib inline,然后.plot()显示

/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, 

和使用ipython notebook --matplotlib=inline显示相同。

+0

认为我们将需要更多信息,显示您的代码,导入和平台... – dartdog 2015-02-07 17:23:32

+0

使用'%matplotlib内联'时描述的错误是由于处理unicode和字符串的问题。可能你有用'latin-1'编码的字符,并且转换尝试使用'decode'。然而,'decode'会使用默认编码'ascii'将您的角色转换为unicode,并且由于该字符在ascii中找不到,转换将失败。你应该尝试使用解码将字符串转换为unicode('“\ xe2”)。解码(encoding ='latin-1')'),然后将该数据传递给matplotlib。 – 2015-02-07 19:52:16

回答

4

变化

ipython notebook --matplotlib=inline 

ipython notebook --matplotlib inline 

通知没有=迹象。

3

我给你举个例子基于以上我的评论:

你有这样的事情:

import matplotlib.pyplot as plt 

%matplotlib inline 

legend = "\xe2" 

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

导致:

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

正如我所说的,这是因为matplotlib想要使用unicode类型的字符串。因此,在绘图过程中,matplotlib尝试使用decode来解码字符串以将其转换为unicode。但是,decodeascii作为默认编码,并且由于您的字符不属于ascii,因此会显示错误。该解决方案是将字符串自己与相应的编码解码:

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

顺便说一句,关于使用ipython notebook --matplotlib inline,它被认为是不好的做法,这样做,因为你是隐藏什么,你在做为了获得最终的笔记本。将%matplotlib inline包含在笔记本中好得多。

0

感谢您的帮助。 我试过以上所有,但没有工作。

这里我发现这是在matplotlib 1.4.x中的fontmanager.py的bug,修复了this开发版的matplotlib,它工作。

我很抱歉,我以前找不到它。谢谢大家。

相关问题