gpt4 book ai didi

python - 使用python按不同颜色的位置绘制图

转载 作者:行者123 更新时间:2023-12-03 21:43:43 25 4
gpt4 key购买 nike

我有一个包含 3 列的数据框,我想用它来绘制图表。

df = pd.DataFrame({
'position': [100,200,220, 300, 400, 500],
'1': list('xoooox'),
'2': list('oxxooo')
})
我在下面画了一个方案
(抱歉添加了图片文件,我很难用文字描述它)
enter image description here
在图中,每个数据的高度无关紧要。
所有的酒吧都是一样的高度
谢谢你。

最佳答案

您可以通过传递 kind='bar' 来做到这一点和 color=some_array , 例如:

df = pd.DataFrame({
'col1': [100, 200, 300, 400],
'col2': [13, 7, 11, 17],
'col3': ['r', 'b', 'g', '0.5'],
})

ax = df.plot(x='col1', y='col2', kind='bar', color=df['col3'])
enter image description here
注意 您可以通过调用 ax 上的方法来进一步修改情节的风格。目的。

关于python - 使用python按不同颜色的位置绘制图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65930306/

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