【发布时间】:2018-03-21 11:07:34
【问题描述】:
好的,我知道这个问题已经被问过很多次了,但我没有得到这个工作:
我尝试在 Ubuntu 16.04 LTS 64-bit 上的 matplotlib 中使用 xkcd-style 和 python 2.7.12 64-位,我使用来自matplotlib.org/xkcd/examples 的示例代码(见下文),但我仍然得到this!
我已经做了什么
- 通过 pip 安装 matplotlib(2.2.2 版)
- 安装 xkcd 和 xkcd 脚本 字体(来自ipython/xkcd-font)
- 安装Humor Sans字体(来自imkevinxu/xkcdgraphs)
- 更新字体缓存数据库 (fc-cache -fv)
- 删除~/.cache/matplotlib(整个目录)
- 重启电脑
- 已验证,字体在 ~/.cache/matplotlib/fontList.json 中
有什么线索可以让这个工作吗?我很感激任何提示!
你好,米夏
我使用来自matplotlib.org/xkcd/examples的示例代码:
from matplotlib import pyplot as plt
import numpy as np
plt.xkcd()
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
plt.xticks([])
plt.yticks([])
ax.set_ylim([-30, 10])
data = np.ones(100)
data[70:] -= np.arange(30)
plt.annotate(
'THE DAY I REALIZED\nI COULD COOK BACON\nWHENEVER I WANTED',
xy=(70, 1), arrowprops=dict(arrowstyle='->'), xytext=(15, -10))
plt.plot(data)
plt.xlabel('time')
plt.ylabel('my overall health')
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax.bar([-0.125, 1.0-0.125], [0, 100], 0.25)
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
ax.xaxis.set_ticks_position('bottom')
ax.set_xticks([0, 1])
ax.set_xlim([-0.5, 1.5])
ax.set_ylim([0, 110])
ax.set_xticklabels(['CONFIRMED BY\nEXPERIMENT', 'REFUTED BY\nEXPERIMENT'])
plt.yticks([])
plt.title("CLAIMS OF SUPERNATURAL POWERS")
plt.show()
【问题讨论】:
-
未应用 xkcd 样式(如您在我的 linked image 中所见),其他一切正常。 :) 但问题已通过接受的答案解决 - 我在使用 matplotlib 2.2 时使用了 matplotlib 1.3 的过时示例。可悲的是,matplotlib 的文档并没有给出您正在查看哪个版本的线索。我的错!
-
啊,对不起,我没有看到链接的图像。一旦您有足够的声誉,您就可以直接在问题中嵌入图像,这样就不会再发生这种情况了:)
标签: python ubuntu matplotlib 64-bit