如何在漏斗图中以绘图方式显示所有数字?

时间:2019-12-29 20:30:11

标签: python plotly

我正在使用plotly做一些漏斗图,但是,当我想在框外显示文本时,左侧没有文本,而右侧只有文本。

设置

from plotly import graph_objects as go


stages = ["Homepage visit", "Search page visit",
           "Payment Page", "Payment Confirmation"]

fig = go.Figure()

fig.add_trace(go.Funnel(
    name = 'Desktop',
    y = stages,
    x = [30100, 27090,  2860,   150],
    textposition = "outside",
    textinfo = "value+percent previous"))

fig.add_trace(go.Funnel(
    name = 'Mobile',
    orientation = "h",
    y = stages,
    x = [15100, 12080,  2718,   302],
    textposition = "outside",
    textinfo = "value+percent previous"))

fig.show()

输出

enter image description here

必填

我想查看所有数字。我同时尝试了“内部”和“外部”,但看不到所有数字。

1 个答案:

答案 0 :(得分:1)

不是,而是这条路,尝试探索constraintext和文本格式:

from plotly import graph_objects as go


stages = ["Homepage visit", "Search page visit",
           "Payment Page", "Payment Confirmation"]

fig = go.Figure()

fig.add_trace(go.Funnel(
    name = 'Desktop',
    y = stages,
    x = [30100, 27090,  2860,   150],
    textposition = "inside",
    textinfo = "value+percent previous"
    , constraintext='outside'

    ,textfont=dict(
        family="sans serif",
        size=14,
        color="black"
    )

)


             )

fig.add_trace(go.Funnel(
    name = 'Mobile',
    orientation = "h",
    y = stages,
    x = [15100, 12080,  2718,   302],
    textposition = "auto",
    textinfo = "value+percent previous"))

fig.show()