简体   繁体   中英

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. However, I would like also to remove the "0%"s labels from the chart. An example:

在此处输入图像描述

How can I do that?

I could fix a limit to the labels using two parameters: uniformtext_minsize and 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:

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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