在 textinfo 注释中进行 plotly 更改

plotly change inside textinfo annotation

问题

在我的漏斗图中,我想将文本信息注释更改为我客户的语言(中文)。更具体地说,我想将“初始”更改为“总体”,将“上一个”更改为“上层”。另外,我也想更改内部值的格式,例如“三千”到“三千”。有什么方法可以做到吗?非常感谢!

代码

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

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

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}上层'
))