Skip to content

Instantly share code, notes, and snippets.

@tracek
Created March 29, 2018 13:04
Show Gist options
  • Save tracek/4896d0123c9001a5c297493ac2801c26 to your computer and use it in GitHub Desktop.
Save tracek/4896d0123c9001a5c297493ac2801c26 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This is a `bqplot` recreation of Mike Bostock's [Wealth of Nations](https://bost.ocks.org/mike/nations/). This was also done by [Gapminder](http://www.gapminder.org/world/#$majorMode=chart$is;shi=t;ly=2003;lb=f;il=t;fs=11;al=30;stl=t;st=t;nsl=t;se=t$wst;tts=C$ts;sp=5.59290322580644;ti=2013$zpv;v=0$inc_x;mmid=XCOORDS;iid=phAwcNAVuyj1jiMAkmq1iMg;by=ind$inc_y;mmid=YCOORDS;iid=phAwcNAVuyj2tPLxKvvnNPA;by=ind$inc_s;uniValue=8.21;iid=phAwcNAVuyj0XOoBL_n5tAQ;by=ind$inc_c;uniValue=255;gid=CATID0;by=grp$map_x;scale=log;dataMin=194;dataMax=96846$map_y;scale=lin;dataMin=23;dataMax=86$map_s;sma=49;smi=2.65$cd;bd=0$inds=;modified=60). It is originally based on a TED Talk by [Hans Rosling](http://www.ted.com/talks/hans_rosling_shows_the_best_stats_you_ve_ever_seen)."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import pandas as pd\n",
"import numpy as np\n",
"import os\n",
"\n",
"from bqplot import (\n",
" LogScale, LinearScale, OrdinalColorScale, ColorAxis,\n",
" Axis, Scatter, Lines, CATEGORY10, Label, Figure, Tooltip\n",
")\n",
"\n",
"from ipywidgets import HBox, VBox, IntSlider, Play, jslink"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"initial_year = 1800"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Cleaning and Formatting JSON Data"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": true,
"scrolled": false
},
"outputs": [],
"source": [
"data = pd.read_json(os.path.abspath('../data_files/nations.json'))"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def clean_data(data):\n",
" for column in ['income', 'lifeExpectancy', 'population']:\n",
" data = data.drop(data[data[column].apply(len) <= 4].index)\n",
" return data\n",
"\n",
"def extrap_interp(data):\n",
" data = np.array(data)\n",
" x_range = np.arange(1800, 2009, 1.)\n",
" y_range = np.interp(x_range, data[:, 0], data[:, 1])\n",
" return y_range\n",
"\n",
"def extrap_data(data):\n",
" for column in ['income', 'lifeExpectancy', 'population']:\n",
" data[column] = data[column].apply(extrap_interp)\n",
" return data"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"data = clean_data(data)\n",
"data = extrap_data(data)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": true,
"scrolled": true
},
"outputs": [],
"source": [
"income_min, income_max = np.min(data['income'].apply(np.min)), np.max(data['income'].apply(np.max))\n",
"life_exp_min, life_exp_max = np.min(data['lifeExpectancy'].apply(np.min)), np.max(data['lifeExpectancy'].apply(np.max))\n",
"pop_min, pop_max = np.min(data['population'].apply(np.min)), np.max(data['population'].apply(np.max))"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def get_data(year):\n",
" year_index = year - 1800\n",
" income = data['income'].apply(lambda x: x[year_index])\n",
" life_exp = data['lifeExpectancy'].apply(lambda x: x[year_index])\n",
" pop = data['population'].apply(lambda x: x[year_index])\n",
" return income, life_exp, pop"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Creating the Tooltip to display the required fields\n",
"\n",
"`bqplot`'s native `Tooltip` allows us to simply display the data fields we require on a mouse-interaction."
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"tt = Tooltip(fields=['name', 'x', 'y'], labels=['Country Name', 'Income per Capita', 'Life Expectancy'])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Creating the Label to display the year\n",
"\n",
"Staying true to the `d3` recreation of the talk, we place a `Label` widget in the bottom-right of the `Figure` (it inherits the `Figure` co-ordinates when no scale is passed to it). With `enable_move` set to `True`, the `Label` can be dragged around. "
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"year_label = Label(x=[0.75], y=[0.10], default_size=46, font_weight='bolder', colors=['orange'],\n",
" text=[str(initial_year)], enable_move=True)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Defining Axes and Scales\n",
"\n",
"The inherent skewness of the income data favors the use of a `LogScale`. Also, since the color coding by regions does not follow an ordering, we use the `OrdinalColorScale`."
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"x_sc = LogScale(min=income_min, max=income_max)\n",
"y_sc = LinearScale(min=life_exp_min, max=life_exp_max)\n",
"c_sc = OrdinalColorScale(domain=data['region'].unique().tolist(), colors=CATEGORY10[:6])\n",
"size_sc = LinearScale(min=pop_min, max=pop_max)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"ax_y = Axis(label='Life Expectancy', scale=y_sc, orientation='vertical', side='left', grid_lines='solid')\n",
"ax_x = Axis(label='Income per Capita', scale=x_sc, grid_lines='solid')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Creating the Scatter Mark with the appropriate size and color parameters passed\n",
"\n",
"To generate the appropriate graph, we need to pass the population of the country to the `size` attribute and its region to the `color` attribute."
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# Start with the first year's data\n",
"cap_income, life_exp, pop = get_data(initial_year)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"wealth_scat = Scatter(x=cap_income, y=life_exp, color=data['region'], size=pop,\n",
" names=data['name'], display_names=False,\n",
" scales={'x': x_sc, 'y': y_sc, 'color': c_sc, 'size': size_sc},\n",
" default_size=4112, tooltip=tt, animate=True, stroke='Black',\n",
" unhovered_style={'opacity': 0.5})"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"nation_line = Lines(x=data['income'][0], y=data['lifeExpectancy'][0], colors=['Gray'],\n",
" scales={'x': x_sc, 'y': y_sc}, visible=False)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Creating the Figure"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"time_interval = 10"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"fig = Figure(marks=[wealth_scat, year_label, nation_line], axes=[ax_x, ax_y],\n",
" title='Health and Wealth of Nations', animation_duration=time_interval)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Using a Slider to allow the user to change the year and a button for animation\n",
"\n",
"Here we see how we can seamlessly integrate `bqplot` into the jupyter widget infrastructure. "
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"year_slider = IntSlider(min=1800, max=2008, step=1, description='Year', value=initial_year)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"When the `hovered_point` of the `Scatter` plot is changed (i.e. when the user hovers over a different element), the entire path of that country is displayed by making the `Lines` object visible and setting it's `x` and `y` attributes."
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def hover_changed(change):\n",
" if change.new is not None:\n",
" nation_line.x = data[data['name'] == wealth_scat.names[change.new]]['income'].values[0]\n",
" nation_line.y = data[data['name'] == wealth_scat.names[change.new]]['lifeExpectancy'].values[0]\n",
" nation_line.visible = True\n",
" else:\n",
" nation_line.visible = False\n",
" \n",
"wealth_scat.observe(hover_changed, 'hovered_point')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"On the slider value `callback` (a function that is triggered everytime the `value` of the slider is changed) we change the `x`, `y` and `size` co-ordinates of the `Scatter`. We also update the `text` of the `Label` to reflect the current year."
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def year_changed(change):\n",
" wealth_scat.x, wealth_scat.y, wealth_scat.size = get_data(year_slider.value)\n",
" year_label.text = [str(year_slider.value)]\n",
"\n",
"year_slider.observe(year_changed, 'value')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Add an animation button"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"play_button = Play(min=1800, max=2008, interval=time_interval)\n",
"jslink((play_button, 'value'), (year_slider, 'value'))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Displaying the GUI"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {
"scrolled": false
},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "3b8da479329a46d6b83e1d7ea75a93a2",
"version_major": 2,
"version_minor": 0
},
"text/html": [
"<p>Failed to display Jupyter Widget of type <code>VBox</code>.</p>\n",
"<p>\n",
" If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean\n",
" that the widgets JavaScript is still loading. If this message persists, it\n",
" likely means that the widgets JavaScript library is either not installed or\n",
" not enabled. See the <a href=\"https://ipywidgets.readthedocs.io/en/stable/user_install.html\">Jupyter\n",
" Widgets Documentation</a> for setup instructions.\n",
"</p>\n",
"<p>\n",
" If you're reading this message in another frontend (for example, a static\n",
" rendering on GitHub or <a href=\"https://nbviewer.jupyter.org/\">NBViewer</a>),\n",
" it may mean that your frontend doesn't currently support widgets.\n",
"</p>\n"
],
"text/plain": [
"VBox(children=(HBox(children=(Play(value=1800, interval=10, max=2008, min=1800), IntSlider(value=1800, description='Year', max=2008, min=1800))), Figure(animation_duration=10, axes=[Axis(label='Income per Capita', scale=LogScale(max=119849.29, min=281.91), side='bottom'), Axis(label='Life Expectancy', orientation='vertical', scale=LinearScale(max=82.87, min=12.7), side='left')], fig_margin={'top': 60, 'bottom': 60, 'left': 60, 'right': 60}, layout=Layout(min_width='125px'), marks=[Scatter(color=array(['Sub-Saharan Africa', 'Sub-Saharan Africa', 'Sub-Saharan Africa',\n",
" 'Sub-Saharan Africa', 'Sub-Saharan Africa', 'Sub-Saharan Africa',\n",
" 'Sub-Saharan Africa', 'Sub-Saharan Africa', 'Sub-Saharan Africa',\n",
" 'Sub-Saharan Africa', 'Sub-Saharan Africa', 'Sub-Saharan Africa',\n",
" 'Sub-Saharan Africa', 'Sub-Saharan Africa', 'Sub-Saharan Africa',\n",
" 'Sub-Saharan Africa', 'Sub-Saharan Africa', 'Sub-Saharan Africa',\n",
" 'Sub-Saharan Africa', 'Sub-Saharan Africa', 'Sub-Saharan Africa',\n",
" 'Sub-Saharan Africa', 'Sub-Saharan Africa', 'Sub-Saharan Africa',\n",
" 'Sub-Saharan Africa', 'Sub-Saharan Africa', 'Sub-Saharan Africa',\n",
" 'Sub-Saharan Africa', 'Sub-Saharan Africa', 'Sub-Saharan Africa',\n",
" 'Sub-Saharan Africa', 'Sub-Saharan Africa', 'Sub-Saharan Africa',\n",
" 'Sub-Saharan Africa', 'Sub-Saharan Africa', 'Sub-Saharan Africa',\n",
" 'Sub-Saharan Africa', 'Sub-Saharan Africa', 'Sub-Saharan Africa',\n",
" 'Sub-Saharan Africa', 'Sub-Saharan Africa', 'Sub-Saharan Africa',\n",
" 'Sub-Saharan Africa', 'Sub-Saharan Africa', 'Sub-Saharan Africa',\n",
" 'South Asia', 'South Asia', 'South Asia', 'South Asia',\n",
" 'South Asia', 'South Asia', 'South Asia', 'South Asia',\n",
" 'Middle East & North Africa', 'Middle East & North Africa',\n",
" 'Middle East & North Africa', 'Middle East & North Africa',\n",
" 'Middle East & North Africa', 'Middle East & North Africa',\n",
" 'Middle East & North Africa', 'Middle East & North Africa',\n",
" 'Middle East & North Africa', 'Middle East & North Africa',\n",
" 'Middle East & North Africa', 'Middle East & North Africa',\n",
" 'Middle East & North Africa', 'Middle East & North Africa',\n",
" 'Middle East & North Africa', 'Middle East & North Africa',\n",
" 'Middle East & North Africa', 'America', 'America', 'America',\n",
" 'America', 'America', 'America', 'America', 'America', 'America',\n",
" 'America', 'America', 'America', 'America', 'America', 'America',\n",
" 'America', 'America', 'America', 'America', 'America', 'America',\n",
" 'America', 'America', 'America', 'America', 'America', 'America',\n",
" 'America', 'America', 'America', 'America', 'America', 'America',\n",
" 'Europe & Central Asia', 'Europe & Central Asia',\n",
" 'Europe & Central Asia', 'Europe & Central Asia',\n",
" 'Europe & Central Asia', 'Europe & Central Asia',\n",
" 'Europe & Central Asia', 'Europe & Central Asia',\n",
" 'Europe & Central Asia', 'Europe & Central Asia',\n",
" 'Europe & Central Asia', 'Europe & Central Asia',\n",
" 'Europe & Central Asia', 'Europe & Central Asia',\n",
" 'Europe & Central Asia', 'Europe & Central Asia',\n",
" 'Europe & Central Asia', 'Europe & Central Asia',\n",
" 'Europe & Central Asia', 'Europe & Central Asia',\n",
" 'Europe & Central Asia', 'Europe & Central Asia',\n",
" 'Europe & Central Asia', 'Europe & Central Asia',\n",
" 'Europe & Central Asia', 'Europe & Central Asia',\n",
" 'Europe & Central Asia', 'Europe & Central Asia',\n",
" 'Europe & Central Asia', 'Europe & Central Asia',\n",
" 'Europe & Central Asia', 'Europe & Central Asia',\n",
" 'Europe & Central Asia', 'Europe & Central Asia',\n",
" 'Europe & Central Asia', 'Europe & Central Asia',\n",
" 'Europe & Central Asia', 'Europe & Central Asia',\n",
" 'Europe & Central Asia', 'Europe & Central Asia',\n",
" 'Europe & Central Asia', 'Europe & Central Asia',\n",
" 'Europe & Central Asia', 'Europe & Central Asia',\n",
" 'Europe & Central Asia', 'Europe & Central Asia',\n",
" 'East Asia & Pacific', 'East Asia & Pacific',\n",
" 'East Asia & Pacific', 'East Asia & Pacific',\n",
" 'East Asia & Pacific', 'East Asia & Pacific',\n",
" 'East Asia & Pacific', 'East Asia & Pacific',\n",
" 'East Asia & Pacific', 'East Asia & Pacific',\n",
" 'East Asia & Pacific', 'East Asia & Pacific',\n",
" 'East Asia & Pacific', 'East Asia & Pacific',\n",
" 'East Asia & Pacific', 'East Asia & Pacific',\n",
" 'East Asia & Pacific', 'East Asia & Pacific',\n",
" 'East Asia & Pacific', 'East Asia & Pacific',\n",
" 'East Asia & Pacific', 'East Asia & Pacific',\n",
" 'East Asia & Pacific', 'East Asia & Pacific',\n",
" 'East Asia & Pacific', 'East Asia & Pacific',\n",
" 'East Asia & Pacific', 'East Asia & Pacific',\n",
" 'East Asia & Pacific'], dtype=object), colors=['steelblue'], default_size=4112, display_names=False, interactions={'hover': 'tooltip'}, names=array(['Angola', 'Benin', 'Botswana', 'Burkina Faso', 'Burundi',\n",
" 'Cameroon', 'Cape Verde', 'Chad', 'Comoros', 'Congo, Dem. Rep.',\n",
" 'Congo, Rep.', \"Cote d'Ivoire\", 'Equatorial Guinea', 'Eritrea',\n",
" 'Ethiopia', 'Gabon', 'Ghana', 'Guinea', 'Guinea-Bissau', 'Kenya',\n",
" 'Lesotho', 'Liberia', 'Madagascar', 'Malawi', 'Mali', 'Mauritania',\n",
" 'Mauritius', 'Mozambique', 'Namibia', 'Niger', 'Nigeria',\n",
" 'Reunion', 'Rwanda', 'Sao Tome and Principe', 'Senegal',\n",
" 'Sierra Leone', 'Somalia', 'South Africa', 'Sudan', 'Swaziland',\n",
" 'Tanzania', 'Togo', 'Uganda', 'Zambia', 'Zimbabwe', 'Afghanistan',\n",
" 'Bangladesh', 'Bhutan', 'India', 'Maldives', 'Nepal', 'Pakistan',\n",
" 'Sri Lanka', 'Algeria', 'Bahrain', 'Djibouti', 'Iraq', 'Israel',\n",
" 'Jordan', 'Kuwait', 'Lebanon', 'Libya', 'Morocco', 'Oman', 'Qatar',\n",
" 'Saudi Arabia', 'Tunisia', 'United Arab Emirates',\n",
" 'West Bank and Gaza', 'Yemen, Rep.', 'Argentina', 'Aruba',\n",
" 'Barbados', 'Belize', 'Bolivia', 'Brazil', 'Canada', 'Chile',\n",
" 'Colombia', 'Costa Rica', 'Cuba', 'Ecuador', 'El Salvador',\n",
" 'French Guiana', 'Grenada', 'Guadeloupe', 'Guatemala', 'Guyana',\n",
" 'Haiti', 'Honduras', 'Jamaica', 'Martinique', 'Mexico',\n",
" 'Netherlands Antilles', 'Nicaragua', 'Panama', 'Paraguay', 'Peru',\n",
" 'Puerto Rico', 'Suriname', 'Trinidad and Tobago', 'United States',\n",
" 'Uruguay', 'Albania', 'Armenia', 'Austria', 'Azerbaijan',\n",
" 'Belarus', 'Belgium', 'Bosnia and Herzegovina', 'Bulgaria',\n",
" 'Croatia', 'Cyprus', 'Denmark', 'Estonia', 'Finland', 'France',\n",
" 'Georgia', 'Germany', 'Greece', 'Hungary', 'Iceland', 'Ireland',\n",
" 'Italy', 'Kazakhstan', 'Latvia', 'Lithuania', 'Luxembourg',\n",
" 'Macedonia, FYR', 'Malta', 'Moldova', 'Montenegro', 'Netherlands',\n",
" 'Norway', 'Poland', 'Portugal', 'Romania', 'Serbia',\n",
" 'Slovak Republic', 'Slovenia', 'Spain', 'Sweden', 'Switzerland',\n",
" 'Tajikistan', 'Turkey', 'Turkmenistan', 'Ukraine',\n",
" 'United Kingdom', 'Uzbekistan', 'Australia', 'Brunei', 'Cambodia',\n",
" 'China', 'Fiji', 'French Polynesia', 'Hong Kong, China',\n",
" 'Indonesia', 'Japan', 'Korea, Dem. Rep.', 'Korea, Rep.',\n",
" 'Macao, China', 'Malaysia', 'Micronesia, Fed. Sts.', 'Mongolia',\n",
" 'Myanmar', 'New Caledonia', 'New Zealand', 'Papua New Guinea',\n",
" 'Philippines', 'Samoa', 'Singapore', 'Solomon Islands', 'Taiwan',\n",
" 'Thailand', 'Timor-Leste', 'Tonga', 'Vietnam', 'Vanuatu'],\n",
" dtype=object), scales={'x': LogScale(max=119849.29, min=281.91), 'y': LinearScale(max=82.87, min=12.7), 'color': OrdinalColorScale(colors=['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b'], domain=['Sub-Saharan Africa', 'South Asia', 'Middle East & North Africa', 'America', 'Europe & Central Asia', 'East Asia & Pacific']), 'size': LinearScale(max=1326856173.0, min=2128.0)}, scales_metadata={'x': {'orientation': 'horizontal', 'dimension': 'x'}, 'y': {'orientation': 'vertical', 'dimension': 'y'}, 'color': {'dimension': 'color'}, 'size': {'dimension': 'size'}, 'opacity': {'dimension': 'opacity'}, 'rotation': {'dimension': 'rotation'}, 'skew': {'dimension': 'skew'}}, size=array([1.5670280e+06, 6.3655900e+05, 1.2100000e+05, 1.6654210e+06,\n",
" 8.9909700e+05, 1.8600540e+06, 5.5716000e+04, 1.4320000e+06,\n",
" 5.6346000e+04, 5.1638190e+06, 3.1446500e+05, 1.0885300e+06,\n",
" 8.0377000e+04, 2.0501000e+05, 2.9489900e+06, 1.5822700e+05,\n",
" 2.0160340e+06, 9.8395900e+05, 2.1816700e+05, 2.5740000e+06,\n",
" 2.7636100e+05, 3.1354300e+05, 1.6830000e+06, 7.3700000e+05,\n",
" 1.4033980e+06, 3.8269600e+05, 1.8100000e+05, 2.0960000e+06,\n",
" 2.2900000e+05, 1.2448610e+06, 1.2100855e+07, 9.2744000e+04,\n",
" 9.2836800e+05, 2.2731000e+04, 1.0098860e+06, 7.9426400e+05,\n",
" 1.0000000e+06, 1.5500000e+06, 5.1560000e+06, 8.6000000e+04,\n",
" 3.0197680e+06, 4.4598500e+05, 2.1013970e+06, 7.4700000e+05,\n",
" 1.0858140e+06, 3.2800000e+06, 2.0000000e+07, 3.9228700e+05,\n",
" 1.7534900e+08, 4.2378000e+04, 3.8810000e+06, 1.3651000e+07,\n",
" 1.2130000e+06, 2.6890000e+06, 6.4474000e+04, 2.2848000e+04,\n",
" 1.0930000e+06, 2.0995400e+05, 2.1700000e+05, 8.1280000e+04,\n",
" 3.3200000e+05, 5.3800000e+05, 2.6890000e+06, 3.1800000e+05,\n",
" 1.4092000e+04, 2.0910000e+06, 8.7500000e+05, 4.0153000e+04,\n",
" 1.6594400e+05, 2.5930000e+06, 5.3400000e+05, 1.9286000e+04,\n",
" 8.1729000e+04, 2.5526000e+04, 1.1000000e+06, 4.5070000e+06,\n",
" 8.1600000e+05, 7.7144700e+05, 1.2060000e+06, 5.3000000e+04,\n",
" 5.7200000e+05, 5.0000000e+05, 2.4800000e+05, 9.8990000e+03,\n",
" 2.9409000e+04, 8.0726000e+04, 5.9500000e+05, 1.6603400e+05,\n",
" 7.2300000e+05, 1.3000000e+05, 4.0100000e+05, 8.4039000e+04,\n",
" 6.5870000e+06, 4.2536000e+04, 1.8600000e+05, 7.8842000e+04,\n",
" 1.4300000e+05, 1.3170000e+06, 1.5500000e+05, 8.0721000e+04,\n",
" 6.0000000e+04, 9.9805100e+06, 5.5000000e+04, 4.3700000e+05,\n",
" 4.1332600e+05, 3.3690000e+06, 8.7996000e+05, 2.3550810e+06,\n",
" 3.4340000e+06, 8.5180600e+05, 2.1870000e+06, 1.2278860e+06,\n",
" 1.8439200e+05, 1.1550000e+06, 3.3413600e+05, 1.1690000e+06,\n",
" 3.1250000e+07, 1.0721780e+06, 2.4905000e+07, 2.3120000e+06,\n",
" 4.1460000e+06, 6.1428000e+04, 5.0526030e+06, 2.0176000e+07,\n",
" 2.0412820e+06, 5.9058800e+05, 7.7865500e+05, 1.2703000e+05,\n",
" 3.9186500e+05, 1.3407200e+05, 7.1255800e+05, 1.2658200e+05,\n",
" 2.3330000e+06, 9.7000000e+05, 1.0426000e+07, 3.2970000e+06,\n",
" 6.3890000e+06, 2.1471970e+06, 2.1406510e+06, 4.6966400e+05,\n",
" 1.2203000e+07, 2.5850000e+06, 1.9860000e+06, 4.6662900e+05,\n",
" 1.0074000e+07, 3.6721500e+05, 1.1215490e+07, 1.6186397e+07,\n",
" 1.9191590e+06, 3.3400000e+05, 2.1280000e+03, 2.0900000e+06,\n",
" 3.8100000e+08, 1.3053300e+05, 6.2530000e+04, 2.0000000e+04,\n",
" 1.7927000e+07, 3.1000000e+07, 4.3450000e+06, 9.3950000e+06,\n",
" 3.5000000e+04, 2.8700000e+05, 1.6416000e+04, 6.1900000e+05,\n",
" 3.5060000e+06, 2.9432000e+04, 1.0000000e+05, 7.5489400e+05,\n",
" 2.1760000e+06, 4.7300000e+04, 3.0000000e+04, 5.6998000e+04,\n",
" 2.0000000e+06, 4.6650000e+06, 1.3726200e+05, 1.8658000e+04,\n",
" 6.5510000e+06, 2.7791000e+04]), stroke='Black', tooltip=Tooltip(fields=['name', 'x', 'y'], labels=['Country Name', 'Income per Capita', 'Life Expectancy']), tooltip_style={'opacity': 0.9}, unhovered_style={'opacity': 0.5}, x=array([ 359.93, 553.72, 407.36, 454.33, 447.59, 517.46, 340. ,\n",
" 400.69, 800.61, 394.03, 387.38, 549.19, 379.13, 583.95,\n",
" 619.21, 377.54, 505.14, 375.96, 345. , 512.93, 364. ,\n",
" 544.65, 434.14, 360. , 427.43, 374.38, 799.61, 358. ,\n",
" 350. , 371.26, 576.38, 692.33, 369. , 674.7 , 420.73,\n",
" 508.4 , 498.83, 759.05, 484.74, 414.04, 470.64, 535.59,\n",
" 461.08, 364.46, 372.82, 472.05, 609. , 539.56, 563. ,\n",
" 472.12, 419.18, 666. , 453.6 , 766.25, 808.99, 380.73,\n",
" 700. , 882.54, 528.69, 661.9 , 932. , 570. , 497.25,\n",
" 882.54, 588.36, 441.27, 518.72, 845.76, 735.45, 661.9 ,\n",
" 871.63, 575.86, 1017.81, 542.97, 695.05, 509.2 , 1159.5 ,\n",
" 702.1 , 522.98, 670.12, 1123.88, 1085.13, 804.31, 819.27,\n",
" 775.67, 760.98, 682.75, 910.69, 503.81, 583.8 , 1350.4 ,\n",
" 944.05, 1053.6 , 698.1 , 726.97, 686.66, 564.16, 697.3 ,\n",
" 775.1 , 1004.13, 774.21, 1912.62, 784.46, 601.22, 502.64,\n",
" 1434.51, 639.95, 717.05, 1554. , 490.82, 836.31, 1227.06,\n",
" 572.78, 1342.84, 906.39, 1037.69, 1388.32, 571.2 , 1695.68,\n",
" 934.41, 1390.67, 801.9 , 1213.16, 1339.84, 585.03, 865.19,\n",
" 988.79, 1145.57, 800.76, 515.5 , 617.12, 1112.36, 2412.43,\n",
" 950. , 1198.39, 1284.41, 1093.92, 1308.87, 1197.6 , 1357.95,\n",
" 1443.02, 1100. , 1612.48, 428.48, 869.92, 513.35, 807.51,\n",
" 2716.87, 346.43, 671.48, 1011.68, 809.23, 985.89, 472.12,\n",
" 809.34, 790.15, 514.12, 1055.06, 698. , 596. , 607.01,\n",
" 750.13, 553.05, 606.93, 569.07, 944.24, 541.62, 573.29,\n",
" 626.97, 1308.44, 861.82, 387.81, 871. , 496.98, 514.12,\n",
" 667.71, 459.71, 829.58]), y=array([26.98, 31. , 33.6 , 29.2 , 31.5 , 28.75, 33.8 , 30.9 , 32.1 ,\n",
" 31.6 , 32.7 , 31.9 , 29.8 , 30.2 , 29.7 , 30.6 , 28. , 29.5 ,\n",
" 29.3 , 25.5 , 32.8 , 31.1 , 30.5 , 30.3 , 29.6 , 32. , 31.2 ,\n",
" 30.28, 32.4 , 30.8 , 30.4 , 51.83, 31.8 , 45.62, 25.2 , 25.1 ,\n",
" 29.4 , 33.5 , 31.4 , 32.3 , 32.2 , 31.3 , 25.3 , 32.6 , 33.7 ,\n",
" 28.21, 25.5 , 36.04, 25.4 , 37.63, 32.8 , 25.9 , 32.6 , 28.8 ,\n",
" 30.3 , 29.9 , 31.2 , 64.17, 31.7 , 26. , 29.7 , 33. , 33.1 ,\n",
" 32.3 , 30.8 , 32.1 , 28.8 , 30.7 , 42.12, 33. , 33.2 , 58.43,\n",
" 54.59, 56.67, 33. , 32. , 39. , 32. , 32. , 30.21, 32.2 ,\n",
" 32.9 , 28.7 , 52.21, 62.44, 54.06, 25.8 , 31.12, 36.27, 33.9 ,\n",
" 34.2 , 54.74, 26.9 , 58.45, 25.4 , 32.9 , 35.5 , 35.7 , 30.43,\n",
" 32.9 , 32.9 , 39.41, 32.9 , 35.4 , 61.94, 34.4 , 57.15, 36.2 ,\n",
" 40. , 35.1 , 35.8 , 36.1 , 38.5 , 35. , 36.5 , 31.8 , 32.4 ,\n",
" 59.8 , 38.37, 36.6 , 36. , 32.4 , 37.7 , 29.01, 26.2 , 33. ,\n",
" 28.9 , 36.9 , 53.09, 64.7 , 57.46, 35.4 , 39.86, 38.8 , 35.9 ,\n",
" 35.6 , 35.7 , 35.5 , 36.4 , 36.6 , 29.5 , 32.16, 38. , 52.31,\n",
" 35. , 50.5 , 36.6 , 40.02, 54.96, 34.05, 29.2 , 35. , 32. ,\n",
" 26.1 , 45.51, 59.22, 30. , 36.4 , 26. , 25.8 , 52.98, 30.6 ,\n",
" 53.78, 31.8 , 30.8 , 51.93, 34.05, 31.5 , 30.9 , 44.9 , 29.1 ,\n",
" 25.7 , 28.3 , 30.4 , 28.97, 57.91, 32. , 40.8 ])), Label(colors=['orange'], default_size=46.0, enable_move=True, font_weight='bolder', interactions={'hover': 'tooltip'}, scales_metadata={'x': {'orientation': 'horizontal', 'dimension': 'x'}, 'y': {'orientation': 'vertical', 'dimension': 'y'}, 'color': {'dimension': 'color'}, 'size': {'dimension': 'size'}, 'opacity': {'dimension': 'opacity'}, 'rotation': {'dimension': 'rotation'}}, text=array(['1800'], dtype='<U4'), tooltip_style={'opacity': 0.9}, x=array([0.75]), y=array([0.1])), Lines(colors=['Gray'], interactions={'hover': 'tooltip'}, scales={'x': LogScale(max=119849.29, min=281.91), 'y': LinearScale(max=82.87, min=12.7)}, scales_metadata={'x': {'orientation': 'horizontal', 'dimension': 'x'}, 'y': {'orientation': 'vertical', 'dimension': 'y'}, 'color': {'dimension': 'color'}}, tooltip_style={'opacity': 0.9}, visible=False, x=array([ 359.93 , 359.93 , 359.93 , 359.93 ,\n",
" 359.93 , 359.93 , 359.93 , 359.93 ,\n",
" 359.93 , 359.93 , 359.93 , 359.93 ,\n",
" 359.93 , 359.93 , 359.93 , 359.93 ,\n",
" 359.93 , 359.93 , 359.93 , 359.93 ,\n",
" 359.93 , 362.03956989, 364.14913978, 366.25870968,\n",
" 368.36827957, 370.47784946, 372.58741935, 374.69698925,\n",
" 376.80655914, 378.91612903, 381.02569892, 383.13526882,\n",
" 385.24483871, 387.3544086 , 389.46397849, 391.57354839,\n",
" 393.68311828, 395.79268817, 397.90225806, 400.01182796,\n",
" 402.12139785, 404.23096774, 406.34053763, 408.45010753,\n",
" 410.55967742, 412.66924731, 414.7788172 , 416.8883871 ,\n",
" 418.99795699, 421.10752688, 423.21709677, 425.32666667,\n",
" 427.43623656, 429.54580645, 431.65537634, 433.76494624,\n",
" 435.87451613, 437.98408602, 440.09365591, 442.20322581,\n",
" 444.3127957 , 446.42236559, 448.53193548, 450.64150538,\n",
" 452.75107527, 454.86064516, 456.97021505, 459.07978495,\n",
" 461.18935484, 463.29892473, 465.40849462, 467.51806452,\n",
" 469.62763441, 471.7372043 , 473.84677419, 475.95634409,\n",
" 478.06591398, 480.17548387, 482.28505376, 484.39462366,\n",
" 486.50419355, 488.61376344, 490.72333333, 492.83290323,\n",
" 494.94247312, 497.05204301, 499.1616129 , 501.2711828 ,\n",
" 503.38075269, 505.49032258, 507.59989247, 509.70946237,\n",
" 511.81903226, 513.92860215, 516.03817204, 518.14774194,\n",
" 520.25731183, 522.36688172, 524.47645161, 526.58602151,\n",
" 528.6955914 , 530.80516129, 532.91473118, 535.02430108,\n",
" 537.13387097, 539.24344086, 541.35301075, 543.46258065,\n",
" 545.57215054, 547.68172043, 549.79129032, 551.90086022,\n",
" 554.01043011, 556.12 , 631.98216216, 707.84432432,\n",
" 783.70648649, 859.56864865, 935.43081081, 1011.29297297,\n",
" 1087.15513514, 1163.0172973 , 1238.87945946, 1314.74162162,\n",
" 1390.60378378, 1466.46594595, 1542.32810811, 1618.19027027,\n",
" 1694.05243243, 1769.91459459, 1845.77675676, 1921.63891892,\n",
" 1997.50108108, 2073.36324324, 2149.22540541, 2225.08756757,\n",
" 2300.94972973, 2376.81189189, 2452.67405405, 2528.53621622,\n",
" 2604.39837838, 2680.26054054, 2756.1227027 , 2831.98486486,\n",
" 2907.84702703, 2983.70918919, 3059.57135135, 3135.43351351,\n",
" 3211.29567568, 3287.15783784, 3363.02 , 3440.9 ,\n",
" 3520.61 , 3598.81 , 3450.82 , 3672.08 ,\n",
" 3549.04 , 3827.94 , 3966.42 , 3917.76 ,\n",
" 4006.21 , 4463.83 , 4269.28 , 4413.6 ,\n",
" 4826.49 , 5102.21 , 5308.14 , 5522.78 ,\n",
" 5346.63 , 5408.12 , 5651.88 , 5526.21 ,\n",
" 5473.29 , 5722.02 , 5470.21 , 3430.85 ,\n",
" 3050.32 , 3008.65 , 3070.82 , 3064.89 ,\n",
" 3074.75 , 2953.41 , 2756.95 , 2584.56 ,\n",
" 2527.47 , 2492.83 , 2220.61 , 2430.21 ,\n",
" 2728.53 , 2730.56 , 2777.42 , 2730.85 ,\n",
" 2627.85 , 1869.92 , 1851.45 , 1989.02 ,\n",
" 2157.35 , 2277.14 , 2384.48 , 2417.18 ,\n",
" 2446.65 , 2479.69 , 2773.29 , 2785.39 ,\n",
" 3007.11 , 3533. , 4069.56 , 4755.46 ,\n",
" 5228.74 ]), y=array([26.98 , 26.98 , 26.98 , 26.98 , 26.98 , 26.98 , 26.98 , 26.98 ,\n",
" 26.98 , 26.98 , 26.98 , 26.98 , 26.98 , 26.98 , 26.98 , 26.98 ,\n",
" 26.98 , 26.98 , 26.98 , 26.98 , 26.98 , 26.98 , 26.98 , 26.98 ,\n",
" 26.98 , 26.98 , 26.98 , 26.98 , 26.98 , 26.98 , 26.98 , 26.98 ,\n",
" 26.98 , 26.98 , 26.98 , 26.98 , 26.98 , 26.98 , 26.98 , 26.98 ,\n",
" 26.98 , 26.98 , 26.98 , 26.98 , 26.98 , 26.98 , 26.98 , 26.98 ,\n",
" 26.98 , 26.98 , 26.98 , 26.98 , 26.98 , 26.98 , 26.98 , 26.98 ,\n",
" 26.98 , 26.98 , 26.98 , 26.98 , 26.98 , 26.98 , 26.98 , 26.98 ,\n",
" 26.98 , 26.98 , 26.98 , 26.98 , 26.98 , 26.98 , 26.98 , 26.98 ,\n",
" 26.98 , 26.98 , 26.98 , 26.98 , 26.98 , 26.98 , 26.98 , 26.98 ,\n",
" 26.98 , 26.98 , 26.98 , 26.98 , 26.98 , 26.98 , 26.98 , 26.98 ,\n",
" 26.98 , 26.98 , 26.98 , 26.98 , 26.98 , 26.98 , 26.98 , 26.98 ,\n",
" 26.98 , 26.98 , 26.98 , 26.98 , 26.98 , 26.98 , 26.98 , 26.98 ,\n",
" 26.98 , 26.98 , 26.98 , 26.98 , 26.98 , 26.98 , 26.98 , 26.98 ,\n",
" 26.98 , 26.98 , 26.98 , 26.98 , 26.98 , 26.98 , 26.98 , 26.98 ,\n",
" 26.98 , 26.98 , 26.98 , 26.98 , 26.98 , 26.98 , 26.98 , 26.98 ,\n",
" 26.98 , 26.98 , 26.98 , 26.98 , 26.98 , 26.98 , 26.98 , 26.98 ,\n",
" 26.98 , 26.98 , 26.98 , 26.98 , 26.98 , 27.204, 27.428, 27.652,\n",
" 27.876, 28.1 , 28.324, 28.548, 28.772, 28.996, 29.22 , 29.42 ,\n",
" 29.81 , 30.21 , 30.6 , 31. , 31.4 , 31.8 , 32.2 , 32.6 ,\n",
" 33. , 33.4 , 33.8 , 34.2 , 34.6 , 35. , 35.4 , 35.8 ,\n",
" 36.2 , 36.6 , 37. , 37.41 , 37.83 , 38.26 , 38.68 , 39.09 ,\n",
" 39.46 , 39.8 , 40.1 , 40.34 , 40.55 , 40.71 , 40.85 , 40.97 ,\n",
" 41.08 , 41.2 , 41.33 , 41.48 , 41.64 , 41.81 , 41.99 , 42.16 ,\n",
" 42.32 , 42.46 , 42.59 , 42.7 , 42.82 , 42.96 , 43.12 , 43.32 ,\n",
" 43.56 , 43.86 , 44.22 , 44.61 , 45.05 , 45.52 , 46.02 , 46.54 ,\n",
" 47.06 ]))], scale_x=LinearScale(allow_padding=False, max=1.0, min=0.0), scale_y=LinearScale(allow_padding=False, max=1.0, min=0.0), title='Health and Wealth of Nations')))"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"VBox([HBox([play_button, year_slider]), fig])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"gist_info": {},
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment