python四分类柱状图
时间: 2023-07-04 16:30:16 浏览: 114
你可以使用Python中的matplotlib库来绘制四分类柱状图。下面是一个简单的例子:
```python
import matplotlib.pyplot as plt
# 数据
categories = ['A', 'B', 'C', 'D']
values_1 = [3, 5, 2, 7]
values_2 = [5, 4, 3, 6]
values_3 = [2, 6, 4, 5]
values_4 = [4, 3, 5, 2]
# 绘图
bar_width = 0.2
plt.bar(categories, values_1, bar_width, label='Data 1')
plt.bar([c + bar_width for c in categories], values_2, bar_width, label='Data 2')
plt.bar([c + bar_width*2 for c in categories], values_3, bar_width, label='Data 3')
plt.bar([c + bar_width*3 for c in categories], values_4, bar_width, label='Data 4')
# 添加标签和标题
plt.xlabel('Category')
plt.ylabel('Value')
plt.title('Four Category Bar Chart')
plt.xticks([c + bar_width*1.5 for c in categories], categories)
# 添加图例
plt.legend()
# 显示图形
plt.show()
```
这段代码将生成一个四分类柱状图,其中每个柱子表示一个类别,并且每个类别有四个相关的值。你可以根据自己的需求更改标签、值和其他绘图参数。
阅读全文
相关推荐
















