使用plot()时,在FontManager中找不到ttf_lookup_cache属性

2024-09-27 22:28:56 发布

您现在位置:Python中文网/ 问答频道 /正文

当我尝试以下操作时(在Python3中):

>>> import matplotlib.pyplot as pl
>>> pl.plot([1, 2, 3])
>>> pl.show()

最后我得到一个错误:

^{pr2}$

但当我执行以下操作时,它会起作用:

>>> from matplotlib.font_manager import FontManager
>>> FontManager().ttf_lookup_cache
{}

但是FontManager构造函数需要一些时间(~1.5s),而第一个代码则没有。在

另外,上面的代码在python2中运行得非常好,我发现一些帖子提出了类似的问题,比如:

……但这些答案对我都不管用。在

如果有帮助的话,我正在用python3.4.3和matplotlib1.3.1开发ubuntu14.04.4。在


Tags: 代码importplotmatplotlibasshow错误manager
1条回答
网友
1楼 · 发布于 2024-09-27 22:28:56

经过大量的挖掘,我意识到问题可能是我使用的matplotlib的旧版本(使用apt-get install安装)。我尝试删除它并使用pip安装它,它成功了:

sudo apt-get remove python3-matplotlib
sudo pip3 install matplotlib

之后,我第一次导入matplotlib.pyplot(关于构建字体缓存)时收到了一条警告。现在一切正常。在

使用pip3安装的matplotlib版本是1.5.1(来自使用apt1.3.1)。在

相关问题 更多 >

    热门问题