python 画两个并列的条状图
时间: 2023-09-01 19:07:25 浏览: 81
好的,以下是Python画两个并列的条状图的代码示例:
```python
import matplotlib.pyplot as plt
import numpy as np
labels = ['A', 'B', 'C', 'D']
men_means = [20, 35, 30, 35]
women_means = [25, 32, 34, 20]
x = np.arange(len(labels))
width = 0.35
fig, ax = plt.subplots()
rects1 = ax.bar(x - width/2, men_means, width, label='Men')
rects2 = ax.bar(x + width/2, women_means, width, label='Women')
ax.set_ylabel('Scores')
ax.set_xticks(x)
ax.set_xticklabels(labels)
ax.legend()
fig.tight_layout()
plt.show()
```
其中,`labels` 为横坐标的标签,`men_means` 和 `women_means` 分别为两个并列的条状图的值。可以根据实际需求修改这些数据。
阅读全文