python柱状图宽度设置
时间: 2023-06-28 21:13:40 浏览: 124
在 Python 中,可以使用 Matplotlib 库来绘制柱状图,并且可以通过设置宽度参数来控制柱子的宽度。
以下是一个简单的示例代码:
```python
import matplotlib.pyplot as plt
# 柱子的名称
labels = ['A', 'B', 'C', 'D', 'E']
# 每个柱子的高度
values = [10, 24, 36, 40, 15]
# 设置柱子的宽度为0.5
width = 0.5
# 绘制柱状图
plt.bar(labels, values, width=width)
# 显示图形
plt.show()
```
在这个示例中,我们通过设置 `width` 参数来控制柱子的宽度,可以根据需要调整这个值。