Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save misterhay/a1c4c318a79b8ecb9afade6db4575abd to your computer and use it in GitHub Desktop.
Save misterhay/a1c4c318a79b8ecb9afade6db4575abd to your computer and use it in GitHub Desktop.
Create a double bar graph from Gapminder data
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