arrbee
arrbee

Reputation: 1

Why is the line border colour of a portion of a Plotly Go pie slice two seperate colours?

I am trying to create a pie chart using Plotly.Go and place it into a Streamlit app. My pie chart is basically complete, and just requires a border colour around each differing slice. I was able to add a border colour to each slice using the marker(line) function but have ran into an issue where one of my slices contains a different colour on the left hand side compared to the rest.

I currently have the following code block which shows how I've created the pie chart:

labels = [f"{total_servicecount[key]} {key.capitalize()}" for key in total_servicecount.keys()]
values = list(total_servicecount.values())

service_colours = {
    'ok': '#173928',
    'warning': '#3E3B16',
    'critical': '#502428',
    'unknown': '#262730',
    'pending': '#28b7e2' 
}

service_colours_bg = {
    'ok': '#35e916',
    'warning': '#FFA500',
    'critical': '#FF0000',
    'unknown': '#808080',
    'pending': '#28b7e2' 
}

fig = go.Figure(data=[go.Pie(
    labels=labels,
    values=values,
    hole=0.7,
    marker=dict(
        colors=list(service_colours.values()),
        line=dict(
            color=list(service_colours_bg.values()),
            width=2
        ),
        pattern=dict(
            bgcolor=list(service_colours_bg.values())
        )
    ),
    pull=[0.01] * len(values),
    hoverinfo='label+percent',
    textinfo='none',
    hovertemplate="<b>%{label}</b><br>Count: %{value}<br>Percentage: %{percent}<extra></extra>",
    domain=dict(x=[0, 1], y=[0, 1]),
    opacity=1                      
)])

fig.update_layout(
    showlegend=False,
    height=200,
    width=190,
    margin=dict(l=0, r=5, t=5, b=5),
    legend=dict(
        orientation='h',
        xanchor='center',
        yanchor='bottom',
        x=0.2,
        y=-0.4
    ),
    annotations=[dict(text='<b>Service<br>Status</b>', x=0.5, y=0.5, font_size=18, showarrow=False)]
)

st.plotly_chart(fig, use_container_width=False)

And here is an image of my pie chart:

Current pie chart showing incorrect border colour on left side of 'warning' slice.

Any and all help would be greatly appreciated, thanks!

Upvotes: 0

Views: 43

Answers (0)

Related Questions