【发布时间】:2011-10-02 07:37:46
【问题描述】:
我有一个条形图代码 sn-p 如下..当你运行它时,你会得到 4 个条,其中第一个位于 y 轴上。是否可以在 y 轴和第一个条之间放置一些间隙?
def plot_graph1():
xvals = range(4)
xnames=["one","two","three","four"]
yvals = [10,30,40,20]
width = 0.25
yinterval = 10
figure = plt.figure()
plt.grid(True)
plt.xlabel('x vals')
plt.ylabel('y vals')
plt.bar(xvals, yvals, width=width)
plt.xticks([ x+(width/2) for x in xvals],[x for x in xnames])
plt.yticks(range(0,max(yvals),yinterval))
figure.savefig("barchart.png",format="png")
plt.show()
if __name__=='__main__':
plot_graph1()
输出如下
任何帮助表示赞赏
谢谢
标记
【问题讨论】:
标签: python matplotlib bar-chart