Home > Enterprise >  How to make a plotly bar graph with the correct value count with python?
How to make a plotly bar graph with the correct value count with python?

Time:10-30

data looks like this

A label
string negative
string negative
string negative
string positive
string positive
string negative
string positive

I want to make a simple plotly bar chart showing two bars - the count of positive and the count of negative, next to each other, blue and red.

If I do this

fig = px.bar(df, x=df["label"])

then I get this (btw do you know why the colors are muted out of nowhere?):

enter image description here

When I hover it says "count = 1 " I want it to say the actual count.. and I want to make the negative bar red. How do I do that?

CodePudding user response:

plotly has histogram chart type. enter image description here

CodePudding user response:

Do groupby and aggregate with count to get a new DataFrame with the count for the two classes under label:

fig = px.bar(df.groupby([‘a’]).count(),x=‘label’,color =‘label’, color_discrete_sequence=[‘blue’,’red’])
  • Related