men_means = (85.5,91.0,72.0,59.0,66.0,55.0) women_means = (94.0,82.0,89.5,62.0,49.0,53.0)绘制堆积柱形图。堆积柱形图的x轴为学科,y轴为平均成绩
时间: 2023-10-21 22:06:19 浏览: 168
左图是重采样对话框我们把分辨率调成米-CA元胞自动机讲义
以下是使用matplotlib库绘制堆积柱形图的代码:
```python
import matplotlib.pyplot as plt
import numpy as np
# 数据
men_means = (85.5, 91.0, 72.0, 59.0, 66.0, 55.0)
women_means = (94.0, 82.0, 89.5, 62.0, 49.0, 53.0)
subjects = ('Math', 'English', 'History', 'Science', 'Art', 'Music')
# 绘图
fig, ax = plt.subplots()
ax.bar(subjects, men_means, label='Men')
ax.bar(subjects, women_means, bottom=men_means, label='Women')
# 图例
ax.legend()
# 标题和轴标签
ax.set_title('Average scores by subject and gender')
ax.set_xlabel('Subjects')
ax.set_ylabel('Average score')
# 显示图形
plt.show()
```
绘制出来的堆积柱形图如下所示:
![stacked_bar_chart.png](https://i.loli.net/2021/05/25/RM1kVIpNmu5SqXc.png)
阅读全文