gpt4 book ai didi

python seaborn barplot 条不居中?

转载 作者:行者123 更新时间:2023-12-04 08:33:01 25 4
gpt4 key购买 nike

我以前从未见过这个,但是我正在制作的 seaborn barplot 不会均匀地间隔条形......

代码

fig, ax = plt.subplots(figsize=(25,6))

sns.barplot(x=value.index, y="CustomerValue", data=value,
order=value.index, hue='Response')

plt.xticks(fontsize=10, rotation=90)

数据

    Response    OrderCount  OrderAvgSize    AvgDeliverCost  AvgOrderValue   CustomerValue
CustomerID
508 Walmart+ 48 22 4.94 14.60 700.80
2007 Both Or None 51 21 4.91 13.46 686.46
698 Walmart+ 47 21 4.91 14.02 658.94
1664 Walmart+ 45 22 4.94 14.60 657.00
475 Walmart+ 45 22 4.94 14.60 657.00
575 Both Or None 51 20 4.87 12.88 656.88
1675 Both Or None 50 20 4.87 12.88 644.00
678 Both Or None 48 20 4.87 12.88 618.24
361 Both Or None 50 19 4.84 12.30 615.00
1627 Walmart+ 41 22 4.94 14.59 598.19
1902 Both Or None 53 17 4.76 11.14 590.42
295 Walmart+ 48 18 4.80 12.28 589.44
269 Both Or None 50 18 4.80 11.72 586.00
1814 Walmart+ 45 19 4.84 12.86 578.70
588 Walmart+ 38 23 4.97 15.17 576.46
2204 Both Or None 49 18 4.80 11.72 574.28
65 Both Or None 54 16 4.71 10.56 570.24
868 Walmart+ 36 24 4.31 15.75 567.00
1436 Walmart+ 42 20 4.87 13.43 564.06
1957 Walmart+ 42 20 4.87 13.43 564.06
1754 Walmart+ 43 19 4.84 12.85 552.55
2036 Walmart+ 43 19 4.84 12.85 552.55
679 Walmart+ 39 21 4.91 14.01 546.39
108 Walmart+ 44 18 4.80 12.28 540.32
605 Both Or None 46 18 4.80 11.72 539.12
1477 Walmart+ 40 20 4.87 13.43 537.20
1737 Walmart+ 38 21 4.91 14.01 532.38
186 Walmart+ 41 19 4.84 12.85 526.85
702 Walmart+ 37 21 4.91 14.01 518.37
1572 Walmart+ 37 21 4.91 14.01 518.37
1797 Walmart+ 38 20 4.87 13.43 510.34
572 Walmart+ 38 20 4.87 13.43 510.34
642 Walmart+ 32 24 4.31 15.74 503.68
1787 Walmart+ 39 19 4.84 12.85 501.15
387 Walmart+ 39 19 4.31 12.85 501.15
991 Walmart+ 39 19 4.84 12.85 501.15
1394 Walmart+ 39 19 4.84 12.85 501.15
1966 Walmart+ 33 23 4.97 15.16 500.28
1053 Walmart+ 35 21 4.91 14.00 490.00
216 Walmart+ 38 19 4.84 12.85 488.30
918 Walmart+ 38 19 4.84 12.85 488.30
1518 Walmart+ 49 14 4.62 9.96 488.04
565 Both Or None 46 16 4.71 10.56 485.76
845 Walmart+ 36 20 4.87 13.43 483.48
1757 Walmart+ 33 22 4.94 14.58 481.14
1983 Walmart+ 33 22 4.94 14.58 481.14
2152 Walmart+ 41 17 4.76 11.69 479.29
198 Both Or None 48 15 4.67 9.98 479.04
1990 Both Or None 48 15 4.67 9.98 479.04
1082 Walmart+ 39 18 4.80 12.27 478.53

知道为什么会这样吗?会不会是有刻度线的东西?我尝试更改大小和旋转无济于事。如果条形均匀分布并直接位于各自的刻度线上方,看起来会更美观。它似乎只在多个蓝色条之后有一个红色条时发生。我不确定要尝试什么来解决这个问题......

enter image description here

最佳答案

那是因为您的数据每个报价只有一个柱,而使用 hue 它应该每个报价有 2 个柱(每个类别一个)。尝试将 dodge=False 传递给 sns.barplot:

sns.barplot(x=value.index, y="CustomerValue", data=value, 
order=value.index, hue='Response', dodge=False)

输出:

enter image description here

关于python seaborn barplot 条不居中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64935694/

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