【发布时间】:2013-12-11 10:39:03
【问题描述】:
这可能是一个微不足道的问题,但我正在尝试使用 matplotlib 和 x 轴上的旋转文本绘制条形图。 我正在使用的代码如下所示:
fig = plt.figure()
x_labels_list = []
for i in range(0, pow(2, N)):
x_labels_list.append(str(f(i))) # The function f() converts i to a binary string
ax = plt.subplot(111)
width = 1.0
bins = map(lambda x: x-width, range(1,pow(2,N)+1))
ax.bar(bins, my_data, width=width)
ax.set_xticks(map(lambda x: x-width/2, range(1,pow(2,N)+1)))
ax.set_xticklabels(x_labels_list, rotation=90, rotation_mode="anchor", ha="right")
效果很好,但是我在 x 轴的右侧得到了一个恼人的空白,如下图的红色椭圆所示:
你知道我怎样才能删除它吗?提前致谢!
【问题讨论】:
-
你能发布一个复制你展示的数字的工作示例吗?
标签: python matplotlib bar-chart