簡體   English   中英

有什么方法可以將漏斗圖中的數字格式化為 Plotly 為 Python?

[英]Is there any way to format the digits in the Funnel chart for Plotly for Python?

我有一個漏斗圖,其中一些值大於 9000,用帶 K 的點符號顯示(末尾表示千)。

我花了 20 分鍾在 Google 和 Plotly 文檔中查找,但未能找到關於如何格式化數字的明確答復。

這是輸入數據

這是我正在使用的代碼

fig = px.funnel(userChurnByEventCategory, x='users', y='event_category', 
    title="User churn", labels={'event_category': 'Event categories'})

fig.show()

這是圖表。 您可以看到最高值帶有字母 K。

如何將所有數字格式化為僅用點(或逗號)分隔千位,並刪除那個令人困惑的 K 字母? 我被要求這樣做。

在此處輸入圖像描述

您可以使用 update_traces 命令和 texttemplate 屬性更新文本格式:

fig = px.funnel(userChurnByEventCategory, x='users', y='event_category', 
    title="User churn", labels={'event_category': 'Event categories'})

fig.update_traces(texttemplate="%{value:,d}")

fig.show()

",d" 部分是您使用 d3 格式的語法實際定義格式的地方

使用“.” 在 fig.show() 之前添加這行代碼而不是“,”作為千位分隔符(因此使用“,”作為小數點分隔符):

# change the thousand separator to . and the decimal seperator to ,
fig.update_layout(separators = ',.')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM