使用从先前讨论的相同的代码的刻度标记,该样品产生下图:matplotlib命名上x轴1,2,4,8,16,等等
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
data = (0, 1890,865, 236, 6, 1, 2, 0 , 0, 0, 0 ,0 ,0 ,0, 0, 0)
ind = range(len(data))
width = 0.9 # the width of the bars: can also be len(x) sequence
p1 = plt.bar(ind, data, width)
plt.xlabel('Duration 2^x')
plt.ylabel('Count')
plt.title('DBFSwrite')
plt.axis([0, len(data), -1, max(data)])
ax = plt.gca()
ax.spines['right'].set_visible(False)
ax.spines['top'].set_visible(False)
ax.spines['left'].set_visible(False)
ax.spines['bottom'].set_visible(False)
plt.savefig('myfig')
而不是刻度标签是0,2,4,6,8 ......我宁愿让它们在每个标记处都标记,然后继续2^x:1,2,4,8,16等等的值。 我怎样才能做到这一点?然后,甚至更好,我可以将标签置于酒吧下方,而不是在左边缘?
+1对于不依赖pyplot的解决方案 –
@PhillipCloud我不明白你的评论。 – tacaswell
@tcaswell我的错误。我认为'FuncFormatter'和'MultipleLocator'不是'pyplot'的一部分,事实证明它们是用'pyplot'导入的。 –