gpt4 book ai didi

python - 如何制作分组条形图

转载 作者:行者123 更新时间:2023-12-01 01:36:24 26 4
gpt4 key购买 nike

我有这个数据框,想将其绘制为分组条形图。我检查了这个问题( Grouped Bar graph Pandas ),它有一个具有其值的组,而不是列。如何获得带柱形的分组条形图?

           num_thread   num_iter       time
category
ORIGINAL 1 100000000 1360.0577
ORIGINAL 1 200000000 2731.8207
ORIGINAL 1 400000000 5440.8003
OMP 2 100000000 692.5336
OMP 2 200000000 1398.5305
OMP 2 400000000 2765.7757
OMP 4 100000000 362.1932
OMP 4 200000000 724.6331
OMP 4 400000000 1447.0628
OMP 8 100000000 193.0222
OMP 8 200000000 382.7540
OMP 8 400000000 759.3889
OMP 16 100000000 102.5276
OMP 16 200000000 214.6385
OMP 16 400000000 450.7183
PTHREAD 2 100000000 697.3113
PTHREAD 2 200000000 1388.6210
PTHREAD 2 400000000 2779.8507
PTHREAD 4 100000000 363.9816
PTHREAD 4 200000000 721.6508
PTHREAD 4 400000000 1432.9843
PTHREAD 8 100000000 189.8591
PTHREAD 8 200000000 379.8860
PTHREAD 8 400000000 764.2684
PTHREAD 16 100000000 124.2015
PTHREAD 16 200000000 238.9460
PTHREAD 16 400000000 478.0660

enter image description here

最佳答案

我认为你需要通过set_index reshape 与 unstack第一:

df1 = df.set_index(['category', 'num_thread', 'num_iter'])['time'].unstack()
#python 3.6+
df1.index = [f'{i}{j}' for i, j in df1.index]
#python under 3.6
#df1.index = ['{}{}'.format(i, j) for i, j in df1.index]
print (df1)
num_iter 100000000 200000000 400000000
OMP2 692.5336 1398.5305 2765.7757
OMP4 362.1932 724.6331 1447.0628
OMP8 193.0222 382.7540 759.3889
OMP16 102.5276 214.6385 450.7183
ORIGINAL1 1360.0577 2731.8207 5440.8003
PTHREAD2 697.3113 1388.6210 2779.8507
PTHREAD4 363.9816 721.6508 1432.9843
PTHREAD8 189.8591 379.8860 764.2684
PTHREAD16 124.2015 238.9460 478.0660

df1.plot.bar()

关于python - 如何制作分组条形图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52361577/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com