简体   繁体   English

从 Python 中的 plotly 饼图中删除“0%”标签

[英]Remove "0%" labels from a plotly pie chart in Python

I need to plot a pie chart that shows all descriptions in a legend, despite the values being zero.我需要 plot 一个饼图,显示图例中的所有描述,尽管值为零。 However, I would like also to remove the "0%"s labels from the chart.但是,我还想从图表中删除“0%”标签。 An example:一个例子:

在此处输入图像描述

How can I do that?我怎样才能做到这一点?

I could fix a limit to the labels using two parameters: uniformtext_minsize and uniformtext_mode:我可以使用两个参数来修复标签的限制:uniformtext_minsize 和 uniformtext_mode:

        fig.update_layout(
        height=400,
        width=430,
        uniformtext_minsize=10, uniformtext_mode='hide',
        legend=dict(font=dict(size=12)),
        margin=dict(
            l=0,
            r=0,
            b=0,
            t=50,
            pad=0
        )

As Plotly adjusts the font size to fit labels inside pie slices, those parameters hide the label if it was impossible to show it inside the slice using uniformtext_minsize font size, as it can be seen below:由于 Plotly 调整字体大小以适合饼图切片内的标签,因此如果无法使用 uniformtext_minsize 字体大小在切片内显示 label,这些参数将隐藏它,如下所示:

在此处输入图像描述

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

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