想法-matplotlib(plot()函数的问题) [英] Enthought - matplotlib (problems with plot() function)
问题描述
我正在尝试在Canopy Express上使用 matplotlib .甚至简单的代码也无法运行...
I am trying to use matplotlib on Canopy Express. Even simple code does not run...
注意:系统无法识别plot(x)
功能.似乎有些东西与ASCII X Unicode有关.我的计算机使用Unicode英语(美国).
NOTE: the system does not recognize the plot(x)
function. It seems there is something with ASCII X Unicode. My computer uses Unicode English(US).
在控制台中,我们有:
C:\Users\dafonseca\AppData\Local\Enthought\Canopy\User\lib\site-packages\matplotlib\font_manager.py in createFontList(fontfiles, fontext)
582 continue
583 try:
--> 584 prop = ttfFontProperty(font)
585 except KeyError:
586 continue
C:\Users\dafonseca\AppData\Local\Enthought\Canopy\User\lib\site-packages\matplotlib\font_manager.py in ttfFontProperty(font)
396 sfnt2 = ''
397 if sfnt4:
--> 398 sfnt4 = sfnt4.decode('ascii').lower()
399 else:
400 sfnt4 = ''
UnicodeDecodeError: 'ascii' codec can't decode byte 0x82 in position 0: ordinal not in range(128)'
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 10)
line, = plt.plot(x, np.sin(x), '--', linewidth=2)
dashes = [10, 5, 100, 5] # 10 points on, 5 off, 100 on, 5 off
line.set_dashes(dashes)
plt.show()
推荐答案
这是已知的 issue 在matplotlib 1.3.0中,涉及到您的一种字体名称中包含非ASCII字符(可能是Æ
字符).
This is a known issue in matplotlib 1.3.0 that relates to having a non-ASCII character in one of your font names (possibly the Æ
character).
您可以找到并删除有问题的字体(最好的主意),或尝试使用以下过程修补安装:
You can either find and remove the offending font (the best idea) or try to patch your installation using the following procedure:
在文本编辑器中打开以下内容:
Open the following in a text editor:
\Users\dafonseca\AppData\Local\Enthought\Canopy\User\lib\site- packages\matplotlib\font_manager.py
搜索sfnt4 = sfnt4.decode('ascii').lower()
并替换为sfnt4 = sfnt4.decode('ascii', 'ignore').lower()
请注意,该错误在下一版matplotlib中将不存在.
Note that this bug won't exist in the next release of matplotlib.
这篇关于想法-matplotlib(plot()函数的问题)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!