Reputation: 21
I'm trying to make a simple graph that displays the responses to a survey question. Normally, the bar graph will show as a solid bar with a total count of the amount represented by the bar, however when I do so, it shows the bar being segmented by the total count. The result is a bar graph that looks like blocks being stacked on top of each other and, when hovering over the bar, only gives a count of 1. Is there a way to change how it looks, or am I just approaching this the wrong way?
And here is my code:
import dash
import pandas as pd
import plotly.express as px
import dash_core_components as dcc
import dash_html_components as html
df = pd.read_csv('dp-export-296620.csv')
df0 = df.EntityType
fig = px.bar(df0, x='EntityType', color='EntityType')
app = dash.Dash(__name__)
app.layout = html.Div([
dcc.Graph(
id = "graph",
figure = fig
)
])
if __name__ == '__main__':
app.run_server(debug=True)
Upvotes: 1
Views: 762
Reputation: 21
I found a fix. There's probably something cleaner but here's what I did.
Instead of simply
df0 = df.EntityType
fig = px.bar(df0, x='EntityType', color='EntityType')
I did the following:
df0 = df['EntityType'].value_counts().rename_axis('EntityType').reset_index(name='counts')
fig = px.bar(df0, x="EntityType", y="counts", color = "EntityType")
I figure that the fix has to do with the reset_index line.
Upvotes: 1