在textinfo注释内进行绘图更改

2024-06-25 23:05:01 发布

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

问题:

在我的漏斗图中,我想将textinfo注释更改为我客户的语言(中文)。更具体地说,我想将“初始”更改为总体", 和“之前”至上层“。此外,我还想更改内部值的格式,例如将“3000”更改为“3”千“.有什么办法吗?非常感谢! enter image description here

代码

from plotly import graph_objects as go

fig = go.Figure()

fig.add_trace(go.Funnel(
    name = 'Label1',
    y = ["stage1", "stage2", "stage3"],
    x = [3000, 2000, 1000],  
    textposition = "inside",
    textinfo = "value+percent previous+percent initial"))

fig.add_trace(go.Funnel(
    name = 'Label2',
    orientation = "h",
    y = ["stage1", "stage2", "stage3"],
    x = [4000, 2500, 1000],    
    textposition = "inside",
    textinfo = "value+percent previous+percent initial"))

fig.update_layout(legend=dict(
    orientation="h",
    yanchor="bottom",
    y=1.02,
    xanchor="right",
    x=0.5
)
                 )

fig.update_traces(textposition='auto', textfont_size=16)

fig.show()s

参考文献

  1. plotly funnel plot api
  2. plotly funnel plot manual

Tags: nameaddgovaluefigtraceplotlypercent
1条回答
网友
1楼 · 发布于 2024-06-25 23:05:01

您可以使用文本模板对其进行自定义。我修改了左侧作为示例

fig.add_trace(go.Funnel(
    name = 'Label1',
    y = \["stage1", "stage2", "stage3"\],
    x = \[3000, 2000, 1000\],  
    textposition = "inside",
    textinfo = "value+percent previous+percent initial",
    texttemplate='%{value}<br>%{percentInitial}总体<br>%{percentPrevious}上层'
))

enter image description here

相关问题 更多 >