2

How does one plot a pie for value_counts() using plotly express for the following series:

import pandas as pd
import string, random
s = pd.Series(random.choice(string.ascii_uppercase) for _ in range(100))

I can see that it can be done through go using:

import plotly.graph_objects as go
go.Figure(data=[go.Pie(labels=s.value_counts().index, values=s.value_counts().values)])

1 Answer 1

4

There are four display types, label, text, value and percentage, which can be combined. Reference page

import plotly.express as px

fig = px.pie(s, values=s.value_counts().values, names=s.value_counts().index)
fig.update_traces(hoverinfo='label+percent', textinfo='value')
fig.show()

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

this doesn't seem to be different from what I have given in second part of my query. I am interested in finding an equivalent in plotly express.
The code has been updated with poorly expressed. The technique is the same.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.