[英]How to change currency format in plotly express hover data?
我一直在嘗試更改懸停數據中這個情節表達數字中的貨幣格式,但沒有任何成功。 我希望將其從美元更改為我的本國貨幣英鎊。 有誰知道我需要做什么來實現這一目標? 文檔並沒有真正涉及到它。
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()
如果我將 $ 符號更改為英鎊符號 (£),這會在圖表工具提示中顯示自定義數據。 據他們說,他們使用 d3 庫進行貨幣格式化,聲稱使用系統語言環境。 我已經檢查過我使用的是正確的語言環境(即 en_GB.utf-8),所以我不知道還要檢查什么?
根據官方網站的示例添加了磅符號作為人口的懸停數據。
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()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.