简体   繁体   English

python - Plot 将分组数据作为 x 轴值的条形图

[英]python - Plot a bar-plot with grouped data as x-axis values

So I have 2 lists, c_val and d_val which I group together in a list called tlt:所以我有 2 个列表,c_val 和 d_val,我将它们组合在一个名为 tlt 的列表中:

c_val = [0.1, 1, 10, 100]
d_val = [1, 2, 3, 4]
tlt = []
for c in c_val:
    for d in d_val:
        tlt.append((c,v))
        
outcome = [0.43, 0.48, 0.50, 0.45, 1, 1.40, 1.30, 1.80, 1.9, 1.10, 1.34, 1.2, 1.24, 0.49, 0.2, 0.93]

Both tlt and outcome lists have 16 values now and I want to plot a barplot with tlt values on the x-axis and outcome on the y-axis, but I get a key error which is due to the fact that the x-axis is a tupple. tlt 和结果列表现在都有 16 个值,我想 plot 一个条形图,tlt 值在 x 轴上,结果在 y 轴上,但我得到一个关键错误,这是由于 x 轴是一个元组。

I am trying to do this with seaborn, but I don't mind doing it with matplotlib if a solution is possible there.我正在尝试用 seaborn 来做这件事,但我不介意用 matplotlib 来做,如果那里有可能的话。

sns.barplot(tlt, accuracies)

Any ideas how to resolve this?任何想法如何解决这个问题?

You can plot it with matplotlib like this你可以用 plot 和 matplotlib 像这样

c_val = [0.1, 1, 10, 100]
d_val = [1, 2, 3, 4]
tlt = []
for c in c_val:
    for d in d_val:
        tlt.append(str((c,d)))
        
outcome = [0.43, 0.48, 0.50, 0.45, 1, 1.40, 1.30, 1.80, 1.9, 1.10, 1.34, 1.2, 1.24, 0.49, 0.2, 0.93]


plt.bar(tlt, outcome, width=0.8, bottom=None)
plt.xticks(rotation=45)

Output Output

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM