-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path01-ChartsNotes.tex
More file actions
189 lines (143 loc) · 5.64 KB
/
01-ChartsNotes.tex
File metadata and controls
189 lines (143 loc) · 5.64 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
\documentclass[a4paper,12pt]{article}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{eurosym}
\usepackage{vmargin}
\usepackage{amsmath}
\usepackage{graphics}
\usepackage{epsfig}
\usepackage{subfigure}
\usepackage{fancyhdr}
\usepackage{listings}
\usepackage{framed}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{chngpage}
%\usepackage{bigints}
%\setcounter{MaxMatrixCols}{10}
\begin{document}
\Large
%%- http://www.analyticsvidhya.com/blog/2015/08/interactive-data-visualization-library-python-bokeh/
\section*{Visualization with Bokeh}
\begin{itemize}
\item Bokeh offers both powerful and flexible features which imparts simplicity and highly advanced customization.
\item It provides multiple visualization interfaces to the user as shown below:\texttt{Bokeh\_Interface}
\end{itemize}
\bigskip
\begin{description}
\item[Charts:] a high-level interface that is used to build complex statistical plots as quickly and in a simplistic manner.
\item[Plotting:] an intermediate-level interface that is centered around composing visual glyphs.
\item[Models:] a low-level interface that provides the maximum flexibility to application developers.
\end{description}
%In this article, we will look at first two interfaces charts and plotting only.
%
%We will discuss models and other advance feature of this library in next post.
%========================================================================%
\newpage
\section*{Charts}
As mentioned above, it is a high level interface used to present information in standard visualization form.
These forms include box plot, bar chart, area plot, heat map, donut chart and many others. You can generate these plots just by passing data frames, numpy arrays and dictionaries.\\
\bigskip
Let’s look at the common methodology to create a chart:
\begin{itemize}
\item Import the library and functions/ methods
\item Prepare the data
\item Set the output mode (Notebook, Web Browser or Server)
\item Create chart with styling option (if required)
\item Visualize the chart
\end{itemize}
%\newpage
%
%To understand these steps better, let me demonstrate these steps using example below:
%
%Charts Example-1:
%
%Create a bar chart and visualize it on web browser using Bokeh
%
%We will follow above listed steps to create a chart:
\newpage
\begin{framed}
\begin{verbatim}
#Import library
from bokeh.charts import Bar, output_file, show
#use output_notebook to visualize it in notebook
# prepare data (dummy data)
data = {"y": [1, 2, 3, 4, 5]}
# Output to Line.HTML
output_file("lines.html", title="line plot example")
#put output_notebook() for notebook
# create a new line chat with a title and axis labels
p = Bar(data, title="Line Chart Example", xlabel='x',
ylabel='values', width=400, height=400)
# show the results
show(p)
\end{verbatim}
\end{framed}
\newpage
\begin{itemize}
\item \textbf{Important:} In the chart above, you can see the tools at the top (zoom, resize, reset, wheel zoom) and these
tools allows you to interact with chart.
\item You can also look at the multiple chart options (legend, xlabel, ylabel, xgrid, width, height and many other) and
various example of charts here.
\end{itemize}
\newpage
%========================================================================%
\section*{Chart Example 2: }
\begin{itemize}
\item Compare the distribution of sepal length and petal length of IRIS data set using
Box plot on notebook
\item To create this visualization, we can import the iris data set using \textbf{\textit{sklearn library}}.
\item Then,
follow the steps as discussed above to visualize chart in ipython notebook.
\end{itemize}
\newpage
\begin{verbatim}
#IRIS Data Set
from sklearn.datasets import load_iris
import pandas as pd
iris = load_iris()
df=pd.DataFrame(iris.data)
df.columns=['petal_width','petal_length',
'sepal_width','sepal_length']
#Import library
from bokeh.charts import BoxPlot,
output_notebook, show
data=df[['petal_length','sepal_length']]
# Output to Notebook
output_notebook()
# create a new line chat with a title and axis labels
p = BoxPlot(data, width=400, height=400)
# show the results
show(p)
Bokeh_Box_Plot
\end{verbatim}
%========================================================================%
\newpage
Chart Example-3: Create a line plot to bokeh server
Prior to plotting visualization to Bokeh server, you need to run it.
If you are using a conda package, you can use run command bokeh-server from any directory
using command. Else, \texttt{python ./bokeh-server} command should work in general. For more detail on this
please refer this link “Deploying Bokeh Server“.
There are multiple benefits of Plotting visualization on Bokeh server:
%================================================================== %
\begin{itemize}
\item Plots can be published to larger audience
\item Visualize large data set interactively
\item Streaming data to automatically updating plots
\item Building dashboards and apps
\end{itemize}
%================================================================== %
To start plotting on Bokeh server, I have executed the command bokeh-server to initialize it followed by
the commands used for visualization.
\begin{framed}
\begin{verbatim}
### Bokeh_Server
from bokeh.plotting import figure, output_server, show
output_server("line")
p = figure(plot_width=400, plot_height=400)
# add a line renderer
p.line([5, 2, 3, 4, 5], [5, 7, 2, 4, 5], line_width=2)
show(p)
% % % %---- Bokeh_Server_Visualization
\end{verbatim}
\end{framed}
\end{document}