-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path02-HighLevelCharts.tex
More file actions
98 lines (82 loc) · 3.08 KB
/
02-HighLevelCharts.tex
File metadata and controls
98 lines (82 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
%nbviewer
%FAQ
%IPython
%Jupyter
%bokeh-notebooks tutorial
%===========================================================================================================%
\section{Bokeh Tutorial — \texttt{bokeh.charts} interface}
\begin{framed}
\begin{verbatim}
In [1]:
import numpy as np
import pandas as pd
from bokeh.io import output_notebook, show
\end{verbatim}
\end{framed}
%===========================================================================================================%
\begin{framed}
\begin{verbatim}
In [2]:
output_notebook()
BokehJS successfully loaded.
\end{verbatim}
\end{framed}
%===========================================================================================================%
\begin{framed}
\begin{verbatim}
In [3]:
from bokeh.charts import Scatter
from bokeh.sampledata.iris import flowers
# fill a data frame with the data of interest and create a groupby object
df = flowers[["petal_length", "petal_width", "species"]]
xyvalues = df.groupby("species")
# any of the following commented are also valid Scatter inputs
#xyvalues = pd.DataFrame(xyvalues)
#xyvalues = xyvalues.values()
#xyvalues = np.array(xyvalues.values())
TOOLS="resize,crosshair,pan,wheel_zoom,box_zoom,reset,previewsave"
scatter = Scatter(xyvalues, tools=TOOLS, ylabel='petal_width')
show(scatter)
inspect
\end{verbatim}
\end{framed}
%===========================================================================================================%
\begin{framed}
\begin{verbatim}
In [4]:
from bokeh.charts import Bar
from bokeh.sampledata.olympics2014 import data
df = pd.io.json.json_normalize(data['data'])
# filter by countries with at least one medal and sort
df = df[df['medals.total'] > 0]
df = df.sort("medals.total", ascending=False)
# get the countries and we group the data by medal type
countries = df.abbr.values.tolist()
gold = df['medals.gold'].astype(float).values
silver = df['medals.silver'].astype(float).values
bronze = df['medals.bronze'].astype(float).values
# build a dict containing the grouped data
medals = pd.DataFrame(dict(bronze=bronze, silver=silver, gold=gold))
bar = Bar(medals, countries, title="Stacked bars", stacked=True)
show(bar)
\end{verbatim}
\end{framed}
%===========================================================================================================%
\begin{framed}
\begin{verbatim}
In [5]:
from bokeh.charts import Histogram
# build some distributions and load them into a dict
mu, sigma = 0, 0.5
normal = np.random.normal(mu, sigma, 1000)
lognormal = np.random.lognormal(mu, sigma, 1000)
# create a pandas data frame from the dict
df = pd.DataFrame(dict(normal=normal, lognormal=lognormal))
hist = Histogram(df, bins=50, legend=True)
show(hist)
ERROR:/Users/bryan/anaconda/envs/bk092/lib/python3.4/site-packages/bokeh/validation/check.py:E-1000 (COLUMN_LENGTHS): ColumnDataSource column lengths are not all the same: ColumnDataSource, ViewModel:ColumnDataSource, ref _id: ec4ff74c-3a90-4ffc-be64-00b876c4df67
In [ ]:
\end{verbatim}
\end{framed}
%===========================================================================================================%
\end{document}