Python 如何更改plotly express悬停数据中的货币格式?
我一直在尝试更改悬停数据中这一图形的货币格式,但没有成功。我想把它从美元换成我的本币,英镑。有人知道我需要做什么才能做到这一点吗?文档中并没有涉及太多内容Python 如何更改plotly express悬停数据中的货币格式?,python,plotly-express,Python,Plotly Express,我一直在尝试更改悬停数据中这一图形的货币格式,但没有成功。我想把它从美元换成我的本币,英镑。有人知道我需要做什么才能做到这一点吗?文档中并没有涉及太多内容 fig = px.bar( df, x=df['cat_level2'], y=df['count'], labels={"cat_level2": "Category", "count": "Product Count", "max":
fig = px.bar(
df,
x=df['cat_level2'],
y=df['count'],
labels={"cat_level2": "Category", "count": "Product Count", "max":"Maximum Price", "mean":"Average Price", "min":"Minimum Price"},
hover_name="cat_level2",
hover_data={"cat_level2":False, "max":":$.2f", "mean":":$.2f", "min":":$.2f"}
)
fig.show()
如果我将$symbols更改为pound symbols(£),这将在图表工具提示中显示customdata。据他们说,他们正在使用d3库进行货币格式化,该库声称使用了系统语言环境。我已经检查了我使用的区域设置是否正确(即en_GB.utf-8),因此我不知道还要检查什么?根据中的示例添加了磅符号作为人口悬停数据
根据中的示例,添加了磅符号作为人口悬停数据
它也适用于HTML实体
£代码>但不是£代码>-hovertemplate='pop:£;%{y} “
。&euro代码>,¥
等,但与流行的
(
)和&代码>(&
)@FurasDash是一个web,因此HTML实体也是有效的。谢谢分享。谢谢大家,非常有帮助-我现在也在尝试将我的customdata放入悬停模板中,这可以不用图形对象完成吗?(例如,我没有使用%{x},而是使用%{customdata[0]:.2f}这样的customdata:fig.update_跟踪(hovertemplate='{x}
产品计数:%%{y}
最高价格:\u00A3%{customdata[0]:.2f}
平均价格:\u00A3%{customdata[1]:.2f}
最低价格:\u00A3%{customdata[2]:.2f})它也适用于HTML实体&
,但不适用于£;
-hovertemplate='pop:&{y}'
。同样适用于€
,¥;
等问题。但适用于流行的(
)和(
)@furas Dash是一个web,所以HTML实体也是有效的。谢谢大家的分享。谢谢大家,非常有用-我现在也在尝试将我的customdata放到悬停模板中,这可以不用图形对象来完成吗?(例如,不用%{x},%%{customdata[0]:.2f}?我用customdata这样做:fig.update_traces)(hovertemplate='{x}
产品数量:%{y}
最高价格:\u00A3%{customdata[0]:.2f}
平均价格:\u00A3%{customdata[1]:.2f}
最低价格:\u00A3%{customdata[2]:.2f})
import plotly.express as px
df = px.data.gapminder().query("continent == 'Europe' and year == 2007 and pop > 2.e6")
fig = px.bar(df, y='pop', x='country')
fig.update_traces(hovertemplate='pop: \u00A3%{y}')
fig.show()