Last active
January 24, 2022 18:32
-
-
Save misterhay/a1c4c318a79b8ecb9afade6db4575abd to your computer and use it in GitHub Desktop.
Create a double bar graph from Gapminder data
This file contains 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
countries = sorted(['Canada','United States','Mexico','Costa Rica','China']) | |
year = '2013' | |
import pandas as pd | |
co2 = pd.read_csv('https://docs.google.com/spreadsheets/d/1VxxG9XJNG5oFXBo_0TTCP_sQ9wEv3Oy5SEOlR_0du5c/export?gid=1415343215&format=csv') | |
electricity = pd.read_csv('https://docs.google.com/spreadsheets/d/1L9CAwtcOoG3WfGkrFOYjAByaznce-DGE1dPK-1-23PU/export?gid=1944428591&format=csv') | |
y1 = co2[co2['country'].isin(countries)][year] | |
y2 = electricity[electricity['country'].isin(countries)][year]/1000 | |
y1_name = 'Carbon Dioxide Emissions per Person' | |
y2_name = 'Electricity Use per Person' | |
xaxis_title = 'Country' | |
yaxis_title = 'Amount' | |
title = 'Carbon Dioxide Emissions and Electricity Use per Person' | |
import plotly.graph_objects as go | |
fig = go.Figure() | |
fig.add_trace(go.Bar(x=countries, y=y1, name=y1_name)) | |
fig.add_trace(go.Bar(x=countries, y=y2, name=y2_name)) | |
fig.update_layout(title_text=title, xaxis_title=xaxis_title, yaxis_title=yaxis_title) | |
fig.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment