简体   繁体   English

数字在 Python Plotly 漏斗中不可见

[英]Numbers are not visible in Python Plotly Funnel

I am plotting a funnel in plotly using python, and even though I have adjusted the font size to 18, the numbers at the really bottom for the red part are very small and arent visible.我正在使用 python 在 plotly 中绘制一个漏斗,即使我已将字体大小调整为 18,红色部分真正底部的数字非常小且不可见。 I am wondering how I can adjust it so that the numbers are on the outside like they are for the green part of the funnel我想知道如何调整它,使数字在外面,就像漏斗的绿色部分一样

在此处输入图像描述

Unfortunately I don't think there is an easy way to achieve what you want.不幸的是,我认为没有一种简单的方法可以实现您想要的。 You could try to hide the text and use annotations, but this isn't easily generalizable as you would need to know ahead of time which values are too small for the text to fit legibly inside of the chart.您可以尝试隐藏文本并使用注释,但这并不容易概括,因为您需要提前知道哪些值太小以至于文本无法清晰地放入图表中。

The best solution I can think of is to use the constraintext = "outside" parameter to force the text to stay the same size regardless of the width for each stage of the funnel, although the text on the left will still be inside the chart.我能想到的最佳解决方案是使用constraintext = "outside"参数强制文本保持相同大小,而不管漏斗每个阶段的宽度如何,尽管左侧的文本仍将在图表内。

As you pointed out, my original suggestion of using textposition = "outside" doesn't work properly (as it places the left text on the right side of the chart), and I believe that this is a bug in the Plotly library.正如您所指出的,我最初使用textposition = "outside"的建议不能正常工作(因为它将左侧文本放在图表的右侧),我相信这是 Plotly 库中的一个错误。

from plotly import graph_objects as go

fig = go.Figure()

fig.add_trace(go.Funnel(
    y = ['a','b','c','d','e','f'],
    x = [135, 62, 47, 20, 2, 1],
    constraintext='outside',
    textfont=dict(
        family="sans serif",
        size=18,
        color="white"
        )
    )
)

fig.add_trace(go.Funnel(
    orientation = "h",
    y = ['a','b','c','d','e','f'],
    x = [298, 145, 120, 87, 11, 2], 
    constraintext='outside',
    textfont=dict(
        family="sans serif",
        size=18,
        color="black"
        )
    )
)

fig.show()

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM