Krisk is created for building statistical interactive visualization with pandas+Jupyter integration on top of Echarts.
In [1]:
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()
Out[1]:
We will be using GapMinder data for examples below.
In [3]:
df = pd.read_csv('http://www.stat.ubc.ca/~jenny/notOcto/STAT545A/'
'examples/gapminder/data/'
'gapminderDataFiveYear.txt', sep='\t')
df.head()
Out[3]:
Let's start by small example. Using bar plot to count the data of category,
In [4]:
kk.bar(df,'continent')
Out[4]:
Note that by default, the plot already used a tooltip. You can hover the plot to see the y-value.
We also can plot bar by averaging GDP per capita for each continent,
In [6]:
kk.bar(df,'continent',y='gdpPercap',how='mean')
Out[6]:
We can change x as year, and use the grouping on continent,
In [7]:
kk.bar(df,'year',y='gdpPercap',c='continent',how='mean')
Out[7]:
Stacked and annotate the chart,
In [8]:
(kk.bar(df,'year',y='gdpPercap',c='continent',how='mean',stacked=True,annotate=True)
.set_size(width=1000))
Out[8]:
Next we can do the same thing with line chart, using area, annotate, and tooltip based on axis,
In [9]:
p = kk.line(df,'year',y='gdpPercap',c='continent',how='mean',
stacked=True,annotate='all',area=True)
p.set_tooltip_style(trigger='axis',axis_pointer='shadow')
p.set_size(width=1000)
Out[9]:
We can also create a histogram and add theme into it,
In [10]:
p = (kk.hist(df,x='lifeExp',c='continent',stacked=True,bins=100))
p.set_tooltip_style(trigger='axis',axis_pointer='shadow')
p.set_theme('vintage')
Out[10]:
Let's get a little bit advanced. We're going to create scatter points of GapMinder data in 2007. We use Life Expectancy, GDP per Capita, and Population as x,y,size respectively. We also want to add the information on the tooltip, add and reposition toolbox, legend, and title.
In [11]:
p = kk.scatter(df[df.year == 2007],'lifeExp','gdpPercap',s='pop',c='continent')
p.set_size(width=1000, height=500)
p.set_tooltip_format(['country','lifeExp','gdpPercap','pop','continent'])
p.set_theme('dark')
p.set_toolbox(save_format='png',restore=True,data_zoom=True)
p.set_legend(orient='vertical',x_pos='-1%',y_pos='-3%')
p.set_title('GapMinder of 2007',x_pos='center',y_pos='-5%')
Out[11]:
In the next few notebooks, we're going to dig deeper at each of the feature, including what's not being discussed here. But this introduction should give a sense of what krisk is capable of.