from ipywidgets import interact, IntSlider
import ipywidgets as widgets
import pandas as pd
import krisk.plot as kk
# Use this when you want to nbconvert the notebook (used by nbviewer)
from krisk import init_notebook; init_notebook()
df = pd.read_csv('../krisk/tests/data/gapminderDataFiveYear.txt',sep='\t')
Krisk also introduced a very simplistic for you to resync data or create a reproducible charts. Consider this plot,
p = kk.bar(df[df.year == 1952],'continent',y='pop', how='mean')
p.set_size(width=800)
Executing this code below
p.resync_data(df[df.year == 2007])
Would let you to modify the plot above instead of returning new plot. As you can see this is useful when you combine it to ipywidgets
to interact with your data.
def resync(year):
return p.resync_data(df[df.year == year])
interact(resync,year=IntSlider(min=df.year.min(),max=df.year.max(),step=5,value=1952))
<function __main__.resync>
You can also replot entirely the plot you have in the cell where the variable is
p.replot(kk.line(df,'continent'))
Finally, there is read_df
method for reproducible charts. You have a plot, and using it to just replace the data. This is especially useful when you have a beautiful chart already, and sharing to others just by replacing the data. Note that this is similar resync_data. But instead of replacing the cell where previous chart contained, it create new cell.
p.read_df(df)