In [1]:
from bokeh.io import output_notebook, show
output_notebook()


Loading BokehJS ...

In [2]:
import bokeh
bokeh.__version__


Out[2]:
'0.12.3'

In [3]:
import pandas as pd

from bokeh.plotting import figure
from bokeh.models import LinearInterpolator
from bokeh.models import ColumnDataSource, HoverTool

In [4]:
data = pd.read_csv('gpm2.csv', index_col='year')
print(data.dtypes)
data.head()


country        object
continent      object
lifeExp       float64
population      int64
gdpPercap     float64
dtype: object
Out[4]:
country continent lifeExp population gdpPercap
year
1952 Afghanistan Asia 28.801 8425333 779.445314
1957 Afghanistan Asia 30.332 9240934 820.853030
1962 Afghanistan Asia 31.997 10267083 853.100710
1967 Afghanistan Asia 34.020 11537966 836.197138
1972 Afghanistan Asia 36.088 13079460 739.981106

In [5]:
source = ColumnDataSource(dict(
    x=data.loc[2007].gdpPercap,
    y=data.loc[2007].lifeExp,
    country=data.loc[2007].country,
    population=data.loc[2007].population,
    continent=data.loc[2007].continent
))

In [6]:
def make_plot():
    return figure(
        tools=[
            HoverTool(tooltips=[('country','@country'),('population','@population{int}')])],
        height=400,
        x_axis_type='log',
        x_range=(100, 100000),
        y_range=(0, 100)
    )

In [7]:
p = make_plot()
size_mapper=LinearInterpolator(
    x=[data.population.min(), data.population.max()],
    y=[5,50]
)
p.circle(
    x='x',y='y', 
    size={'field':'population', 'transform': size_mapper},
    alpha=0.6,
    source=source
)
show(p)



In [8]:
p = make_plot()
size_mapper=LinearInterpolator(
    x=[data.population.min(), data.population.max()+1],
    y=[5,50]
)
p.circle(
    x='x',y='y', 
    size={'field':'population', 'transform': size_mapper},
    alpha=0.6,
    source=source
)
show(p)



In [ ]: