以下是一种使用 Python 中的 matplotlib 库绘制条形图的方法,用于对比不同组别在不同时间段的得分情况:

import matplotlib.pyplot as plt

# 数据
data1 = [89.90114387, 91.9463064]
data2 = [83.74391917354532, 84.33594119443825]
data3 = [84.3643001908087, 84.60568656086004]
data4 = [89.51332814241476, 90.72521335237178]

# x轴标签
labels = ['10days', '20days']

# 绘图
x = range(len(labels))
width = 0.35
fig, ax = plt.subplots()
rects1 = ax.bar(x - width/2, data1, width, label='Group 1')
rects2 = ax.bar(x + width/2, data2, width, label='Group 2')
rects3 = ax.bar(x + 3*width/2, data3, width, label='Group 3')
rects4 = ax.bar(x + 5*width/2, data4, width, label='Group 4')

# 添加标签、标题、图例
ax.set_ylabel('Scores')
ax.set_xlabel('Days')
ax.set_title('Scores by Days and Groups')
ax.set_xticks(x + 2*width)
ax.set_xticklabels(labels)
ax.legend()

# 显示图形
plt.show()

运行代码后,将产生如下的条形图:

bar_chart.png

该条形图展示了四组数据在 10 天和 20 天的得分情况。每组数据用不同颜色的条形表示,便于观察和对比。

Python Matplotlib 柱状图绘制:对比不同组别数据

原文地址: https://www.cveoy.top/t/topic/nIvh 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录