-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdash-tutorial-3.py
More file actions
41 lines (34 loc) · 1.09 KB
/
Copy pathdash-tutorial-3.py
File metadata and controls
41 lines (34 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import dash
import dash_core_components as dcc
import dash_html_components as html
import pandas as pd
import plotly.graph_objs as go
app = dash.Dash()
df = pd.read_csv(
'https://gist.githubusercontent.com/chriddyp/5d1ea79569ed194d432e56108a04d188/raw/a9f9e8076b837d541398e999dcbac2b2826a81f8/gdp-life-exp-2007.csv')
data = []
for i in df.continent.unique():
trace = go.Scatter(
x=df[df['continent'] == i]['gdp per capita'],
y=df[df['continent'] == i]['life expectancy'],
text=df[df['continent'] == i]['country'],
mode='markers',
opacity=0.7,
marker={'size': 15,
'line': {'width': 0.5, 'color': 'black'}},
name=i)
data.append(trace)
layout = go.Layout(
xaxis={'type': 'log', 'title': 'GDP Per Capita'},
yaxis={'title': 'Life Expectancy'},
margin={'l': 40, 'b': 40, 't': 10, 'r': 10},
legend={'x': 0, 'y': 1},
hovermode='closest')
app.layout = html.Div([
dcc.Graph(
id='life-exp-vs-gdp',
figure={'data': data, 'layout': layout}
)
])
if __name__ == '__main__':
app.run_server()