简体   繁体   English

无法在matplotlib中绘制条形图

[英]Can't get bar chart to plot in matplotlib

Using this code, 使用此代码,

x = [420.0, 4353.0, 4373.0]; y = [269.0, 252.0, 283.0]
plt.bar(x,y)
plt.show()

I get: 我明白了:

空条形图

Where are the bars? 酒吧在哪里? How do I get them to show up? 我如何让他们出现?

By default, each bar is plotted with a width of 0.8 and due to the large range of x values on your plot, that is too narrow to be visible when rendered. 默认情况下,每个条形图的宽度均为0.8并且由于绘图中的x值范围较大,因此在渲染时太窄而无法显示。 You'll instead want to specify a larger width using the width kwarg 相反,您需要使用width kwarg指定更大的width

plt.bar(x, y, width=20)

在此输入图像描述 You an also use an array for the width value to specify a different width for each bar 您还可以使用数组作为width值,为每个条指定不同的宽度

plt.bar(x, y, width=[3000, 20, 20])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM