我有以下Pandas 数据框

import pandas as pd
foo = pd.DataFrame({'country': {0: 'a', 1: 'b', 2: 'c', 3: 'd', 4: 'e'},
 'unweighted': {0: 18.0, 1: 16.9, 2: 13.3, 3: 11.3, 4: 13.1},
 'weighted_1': {0: 17.7, 1: 15.8, 2: 14.0, 3: 11.2, 4: 12.8},
 'weighted_2': {0: 17.8, 1: 15.8, 2: 14.0, 3: 11.2, 4: 12.8}})

country unweighted  weighted_1  weighted_2
0   a   18.0    17.7    17.8
1   b   16.9    15.8    15.8
2   c   13.3    14.0    14.0
3   d   11.3    11.2    11.2
4   e   13.1    12.8    12.8

我正在使用以下代码生成条形图,该条形图使用plotly_express

import plotly.express as px
px.bar(
    so,
    x='country',
    y=['unweighted', 'weighted_1', 'weighted_2'],
    barmode='group',
)

enter image description here

我还想在每个wine 吧展示text美元. 我试过了

px.bar(
        so,
        x='country',
        y=['unweighted', 'weighted_1', 'weighted_2'],
        text=['unweighted', 'weighted_1', 'weighted_2'],
        barmode='group',
    )

但它不起作用.

我怎么能这么做呢?

推荐答案

批注中有自动批注.

import plotly.express as px
px.bar(
    foo,
    x='country',
    y=['unweighted', 'weighted_1', 'weighted_2'],
    text_auto=True,
    barmode='group',
)

enter image description here

Python相关问答推荐

Python-Polars:如何用两个值的平均值填充NA?

在for循环中保存和删除收件箱

如何使用关键参数按列对Pandas rame进行排序

Python中两个矩阵的自定义Hadamard风格产物

pyautogui.locateOnScreen在Linux上的工作方式有所不同

使用GEKKO在简单DTE系统中进行一致初始化

在Python和matlab中显示不同 colored颜色 的图像

如何从具有多个嵌入选项卡的网页中Web抓取td类元素

仅从风格中获取 colored颜色 循环

在Python中对分层父/子列表进行排序

Python在tuple上操作不会通过整个单词匹配

我在使用fill_between()将最大和最小带应用到我的图表中时遇到问题

不理解Value错误:在Python中使用迭代对象设置时必须具有相等的len键和值

如何在虚拟Python环境中运行Python程序?

将tdqm与cx.Oracle查询集成

调用decorator返回原始函数的输出

在Python 3中,如何让客户端打开一个套接字到服务器,发送一行JSON编码的数据,读回一行JSON编码的数据,然后继续?

启动带有参数的Python NTFS会导致文件路径混乱

Polars将相同的自定义函数应用于组中的多个列,

如何使用OpenGL使球体遵循Python中的八样路径?