Mic*_*cha 9 python ubuntu 64-bit matplotlib
好的,我知道这个问题已经被问过很多次了,但是我没有这个问题:
我尝试在matbulotlib上使用xkcd-style在Ubuntu 16.04 LTS 64位上使用python 2.7.12 64位,我使用matplotlib.org/xkcd/examples中的示例代码(见下文),但我仍然得到这个!
我做了什么
我有什么线索可以让这个工作?我很感激任何暗示!
问候,米哈
我使用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()
Run Code Online (Sandbox Code Playgroud)
似乎matplotlib使用上下文的方式发生了变化.一个工作版本应该是手动使用上下文,
with plt.xkcd():
# your plot here
plt.show()
Run Code Online (Sandbox Code Playgroud)
然后该示例将如下所示:
from matplotlib import pyplot as plt
import numpy as np
with 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')
plt.show()
Run Code Online (Sandbox Code Playgroud)