Home > other >  Choropleth us-states map showing incorrect data and color coding
Choropleth us-states map showing incorrect data and color coding

Time:03-17

I am trying to show hospitals by type in US states. The dataset I am using is here enter image description here

enter image description here

CodePudding user response:

I have not verified this in the Dash environment, but I believe the operation will be the same. The cause is that you are specifying a state column for the entire data frame you are setting up. The easiest response is to target the filtered data frame.

import plotly.graph_objects as go
import pandas as pd

df = pd.read_csv('./data/Hospitals.csv')
varname = 'CRITICAL ACCESS'
filtered_df = df[df["TYPE"] == varname]["STATE"].value_counts().to_frame('value')
#print(filtered_df)
fig = go.Figure(data=go.Choropleth(
    locations=filtered_df.index, 
    z = filtered_df['value'], 
    locationmode = 'USA-states', 
    colorscale = 'Blues',
    colorbar_title = "Count",
))

fig.update_layout(
    title_text = f'Hospitals of {varname}',
    geo_scope='usa', 
    width=1200,
    height=800
)

fig.show()

enter image description here

  • Related