Skip to content

Instantly share code, notes, and snippets.

@karanjagota
Created June 10, 2019 16:50
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 karanjagota/18db9d644a2c1c417a82d2a90a9acabf to your computer and use it in GitHub Desktop.
Save karanjagota/18db9d644a2c1c417a82d2a90a9acabf to your computer and use it in GitHub Desktop.
bar graph example with plotly for medium blogs
df = pd.read_csv('lf.csv')
df.head()
subset_df = df[df.year>=2010]
years = df.year.unique()
trace1 = go.Bar(x=subset_df[subset_df['country']=='india']['Lf-overall'],
y=years,
orientation='h',
name="India")
trace2 = go.Bar(x=subset_df[subset_df['country']=='usa']['Lf-overall'],
y=years,
orientation='h',
name="USA")
data = [trace1,trace2]
layout = go.Layout(title = 'Life Expectency Comparison between USA and India',
xaxis=dict(title='Life Expectency Age'),
yaxis=dict(title='Years'),
width=800,
height=450)
fig = go.Figure(data=data,layout=layout)
pyo.plot(fig,filename='bar.html')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment