Created
November 27, 2020 03:45
-
-
Save ThiagoFPMR/8ffdb3140d7c4980183d7d03194af752 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def scatter_y_label (var): | |
if var == 'total_cases': | |
return 'Percentage Infected' | |
elif var == 'total_tests': | |
return 'Percentage Tested' | |
elif var == 'total_deaths': | |
return 'Percentage Dead' | |
elif var == 'total_recovered': | |
return 'Percentage Recovered' | |
# Variable VS Education Level Scatter Plot | |
@app.callback(Output('covid-vs-edu', 'figure'), | |
[Input('population-slider', 'value'), | |
Input('interest-variable', 'value')]) | |
def update_scatter(selected_pop, interest_var): | |
sorted = data[data.population <= selected_pop] | |
fig = px.scatter(sorted, | |
x='expected_years_of_school', | |
y=sorted[interest_var]/sorted.population, | |
size='population', | |
color='income_group', | |
hover_name='country', | |
template='plotly_white', | |
labels={'expected_years_of_school':'Expected Years of School', | |
'y': scatter_y_label(interest_var)}, | |
title='Total Cases VS Education Level') | |
fig.update_layout(transition_duration=500) | |
return fig | |
# Variable Per Income Group Bar Chart | |
@app.callback(Output('covid-vs-income', 'figure'), | |
[Input('population-slider', 'value'), | |
Input('interest-variable', 'value')]) | |
def update_income_bar(selected_pop, interest_var): | |
sorted = data[data.population <= selected_pop].groupby(by='income_group').sum().reset_index() | |
fig = px.bar(sorted, | |
x='income_group', | |
y=interest_var, | |
color='income_group', | |
template='plotly_white', | |
labels={'income_group':'Income Group', | |
'total_cases':'Total Cases', | |
'total_tests':'Total Tests', | |
'total_deaths':'Total Deaths', | |
'total_recovered':'Total Recovered'}, | |
title='Total Cases By Income Group') | |
fig.update_layout() | |
return fig | |
# Variable Per Country Bar Chart | |
@app.callback(Output('covid-vs-income2', 'figure'), | |
[Input('population-slider', 'value'), | |
Input('interest-variable', 'value')]) | |
def update_country_bar(selected_pop, interest_var): | |
sorted = data[data.population <= selected_pop] | |
fig = px.bar(sorted, | |
x='country', | |
y=interest_var, | |
color='income_group', | |
template='plotly_white', | |
labels={'country':'Country', | |
'total_cases':'Total Cases', | |
'total_tests':'Total Tests', | |
'total_deaths':'Total Deaths', | |
'total_recovered':'Total Recovered'}, | |
title='Total Cases per Country') | |
fig.update_layout() | |
return fig |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment