In [1]:
from bokeh.io import output_notebook, show
output_notebook()
In [2]:
import bokeh
bokeh.__version__
Out[2]:
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()
Out[4]:
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 [ ]: