| Total Complexity | 0 |
| Total Lines | 49 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import dash |
||
| 2 | import dash_core_components as dcc |
||
| 3 | import dash_html_components as html |
||
| 4 | import pandas as pd |
||
| 5 | import plotly.graph_objs as go |
||
| 6 | |||
| 7 | external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css'] |
||
| 8 | |||
| 9 | app = dash.Dash(__name__, external_stylesheets=external_stylesheets) |
||
| 10 | |||
| 11 | df = pd.read_csv( |
||
| 12 | 'https://gist.githubusercontent.com/chriddyp/' + |
||
| 13 | '5d1ea79569ed194d432e56108a04d188/raw/' + |
||
| 14 | 'a9f9e8076b837d541398e999dcbac2b2826a81f8/'+ |
||
| 15 | 'gdp-life-exp-2007.csv') |
||
| 16 | |||
| 17 | |||
| 18 | app.layout = html.Div([ |
||
| 19 | dcc.Graph( |
||
| 20 | id='life-exp-vs-gdp', |
||
| 21 | figure={ |
||
| 22 | 'data': [ |
||
| 23 | go.Scatter( |
||
| 24 | x=df[df['continent'] == i]['gdp per capita'], |
||
| 25 | y=df[df['continent'] == i]['life expectancy'], |
||
| 26 | text=df[df['continent'] == i]['country'], |
||
| 27 | mode='markers', |
||
| 28 | opacity=0.7, |
||
| 29 | marker={ |
||
| 30 | 'size': 15, |
||
| 31 | 'line': {'width': 0.5, 'color': 'white'} |
||
| 32 | }, |
||
| 33 | name=i |
||
| 34 | ) for i in df.continent.unique() |
||
| 35 | ], |
||
| 36 | 'layout': go.Layout( |
||
| 37 | xaxis={'type': 'log', 'title': 'GDP Per Capita'}, |
||
| 38 | yaxis={'title': 'Life Expectancy'}, |
||
| 39 | margin={'l': 40, 'b': 40, 't': 10, 'r': 10}, |
||
| 40 | legend={'x': 0, 'y': 1}, |
||
| 41 | hovermode='closest' |
||
| 42 | ) |
||
| 43 | } |
||
| 44 | ) |
||
| 45 | ]) |
||
| 46 | |||
| 47 | if __name__ == '__main__': |
||
| 48 | app.run_server(debug=True) |
||
| 49 |