将钢筋相互叠放在一起

2024-07-05 14:13:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直在使用条形图进行数据可视化,虽然我遇到了一个问题,但我在其他地方找不到任何帮助。以下是我目前得到的图像: Comparing laptops according to their price

这是生成图表的代码:

df = pd.read_csv('laptops.csv')

        fig_a = px.bar(df, y='Price', x='Laptops', title='Comparing the cost of each laptop.')
        fig_a.update_layout(
            height=800,
            width=800,
            margin=dict(
                l=50,
                r=50,
                b=100,
                t=100,
                pad=4,
            ),
            xaxis_categoryorder='total descending',
            barmode='relative'
        )

        fig_a.write_image('plots/laptops1.png')

所以,问题是一些笔记本电脑的名称是相同的,唯一的区别是它们的价格。Plotly会自动将它们堆叠在一起,这是我不想要的。即使x轴值(笔记本电脑)相等,是否有办法单独显示每个条?我尝试使用barmode并给出不同的值,比如“group”或“relative”,但没有任何变化

提前谢谢


Tags: csvto数据图像df可视化地方fig