0% found this document useful (0 votes)
39 views42 pages

BOKEH

-

Uploaded by

lishanthigak
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views42 pages

BOKEH

-

Uploaded by

lishanthigak
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 42

UNIT 3

BOKEH
What is Bokeh?

• Python library
• To create an interactive visualizations
• Build beautiful graphics
• Without any javascript, we create a javascript coding for visualizations.
• Powerful tools for data visualizations
• Provides elegant ,concise, high performance with streaming datasets
Features
• Flexibility: It is used for common plotting requirements and used as a complex use cases
• Productivity: Bokeh can be easily interact with popular pydata tools such as Pandas and
Jupyter Notebook
• Interactivity: Bokeh creates interactive plots that change when the user interacts with them.
• Powerful: By adding custom Javscript,it is possible to generate visualizations for specialized
use-cases.
• Sharable: rendered in Jupyter notebooks
• Open source:Free to use
Simple representation
Plots with glyphs

• Plots is made up of geometrical shapes like circle,line,rectangle etc.


• Geometrical shapes called glyphs
• Plots constructed using bokeh.plotting interface use a tools and styles
• It represents the visual information about the corresponding data shapes
like Patch plot,Bar plot,Scatter plot, line plot
Where to use Bokeh charts?

• With bokeh, we can embed the charts on the web, and make a live
dashboard, and apps.
• Bokeh provides its own styling option and widgets for the charts.
• This is the advantage of embedding the bokeh charts on and website using
Flask or Django.
Benefits of Bokeh

• Bokeh allows you to build complex statistical plots quickly and through simple
commands
• Bokeh provides you output in various medium like html, notebook and server
• We can also embed Bokeh visualization to flask and django app
• Bokeh can transform visualization written in other libraries like matplotlib, seaborn,
ggplot
• Bokeh has flexibility for applying interaction, layouts and different styling option to
visualization
Challenges of Bokeh
• In the future, we have a lot of development in Bokeh
• Code is reusable for future enhancement
• Less visualization options when compared to D3.js
Different forms
Steps to visualize a plot
1. Import the library and functions/ methods
2. Prepare the data
3. Set the output mode (Notebook, Web Browser, or Server)
4. Create a chart with a styling option (if required)
5. Visualize the chart
Bokeh Interface
• Provides a simple interface for users like domain experts.
• Layered approach and offers programming interfaces to different uses.
• Two interfaces.
• Bokeh. plotting
• Bokeh. models
The bokeh.plotting interface
• It is a primary interface.
• It focuses on relating glyphs to data.
• It automatically assembles plots with default elements such as axes, grids,
and tools.
• Figure() function is core of bokeh.plotting interface.
• This function adding different kinds of glyphs to plot
• It gives axes,grids,tools
The bokeh.model interface
• This module is a low-level interface.
• It provides a great deal of flexibility to the application developer in developing
visualizations.
• A Bokeh plot results in an object containing visual and data aspects of a scene
which is used by the BokehJS library.
• The low-level objects that comprise a Bokeh scene graph are called Models.
Basic types of plots
• Line plot:The line() method of Figure object adds a line glyph to the
Bokeh figure. It needs x and y parameters as data arrays for showing their
linear relationship.
• Bar plot:The figure object has two different methods for constructing bar
plot
• Hbar() Horizontal across plot width()
• Parameters height,right,left
Basic types of plots
• Vbar() shows vertical plot height
Parameters: width,top,bottom
• Patch plot:A plot which shades a region of space in a specific color to
show a region or a group having similar properties is termed as a patch
plot in Bokeh.
• Figure object has patch() and patches() methods for this purpose.

• Parameters: X and y coordinates


Basic types of plots
• Patches() This method is used to draw multiple polygonal patches.
• Scatter markers:Scatter plots are very commonly used to determine the bi-
variate relationship between two variables. The enhanced interactivity is
added to them using Bokeh. Scatter plot is obtained by calling scatter()
method of Figure object.

• Parameters:X,y,size,marker,color
Types of constants
• Diamond • Asterisk

• DiamondCross • Circle
• CircleCross
• Hex
• CircleX
• InvertedTriangle
• Cross
• Square • Dash
• SquareCross • Triangle
• SquareX • X
Plotting area plots

• filled regions between two series in common areas


• It has two classes harea() and varea()
• varea(): It is used for the vertical directed area which has one coordinate
x, two coordinates y1 and y2
Syntax:varea(x,y1,y2)
harea(): It is used for the horizontal directed area which has two coordinate x1 and x2,
one coordinate y1
Syntax:harea(x1,x2,y)
Circle glyphs
• The circle() method adds a circle glyph to the figure and needs x and y coordinates of its
center.
• it can be configured with the help of parameters such as fill_color, line-color, line_width etc.
circle_cross()
• The circle_cross() method adds circle glyph with a ‘+’ cross through the center.
circle_x()
• The circle_x() method adds circle with an ‘X’ cross through the center.
Rectangle,Oval,Polygons
• The rect() method of Figure class adds a rectangle glyph based on x and y
coordinates of center, width and height.
• The square() method on the other hand has size parameter to decide
dimensions.
• The ellipse() and oval() methods adds an ellipse and oval glyph. They use
similar signature to that of rect() having x, y,w and h parameters.
Wedges and arcs
• The arc() method draws a simple line arc based on x and y coordinates,
start and end angles and radius. Angles are given in radians whereas radius
may be in screen units or data units. The wedge is a filled arc.
• The wedge() method has the same properties as arc() method. Both
methods have provision of optional direction property which may be clock
or anti clock that determines the direction of arc/wedge rendering. The
annular_wedge() function renders a filled area between to arcs of inner
and outer radius.
Bokeh Server
• Easy to create interactive web applications that connect front end UI
events to running python code
• It creates high-level python models such as plots,ranges,axes,glyphs.
• It is also have a some advantages,easy to have other languages such as R
or scala which helps to visualize the browser
• It purpose is synchronize data between the underlying python environment
and Bokeh JS library running in the browser
Use case scenarios
• Local or individual use:
Use a bokeh server for exploratory data analysis in Jupyter
Notebook,it can run easily.
It is easy to use and more convenient to allowing quick and simple
deployment through effective use of Bokeh server applications
• Creating deployable applications:
Create an interactive data visualizations and create a applications
Bokeh server can interact with app directly
Building Bokeh Applications
• Bokeh server is to create Bokeh applications and serve them with Bokeh
serve command.
• It uses the application code to create sessions and documents for all
connecting browsers.
Architecture
Explanation
• The Bokeh server executes the application code with every new
connection and creates a new Bokeh document, syncing it to the browser.
• The application code also sets up the callbacks that should run whenever
properties, such as widget values, change.
Code
Activate Bokeh server
Graph for frequency 1
Graph for frequency 2
Geoplotlib
• It is a Python open source toolbox used for visualizing geographical plots and data.
• It is a simple powerful API produces visualization on Open Street Map tiles.
• Using packages as Numpy and Scipy for numerical computations and pyglet as
graphical rendering
Principles of geoplotlib
• There are 3 principles,
 Simplicity: it minimizes the complexity by providing a set of built-in
tools for the tasks such as density visualization, spatial graphs, and shapefiles.
 Integration: it supports complete integration with the rich python data analysis
such as scientific computing, ML, and numerical packages. The visualization
can even run within an IPython session supporting interactive data analysis and
facilitating the iterative design for visualizations.
 Performance, this tool allows visualization to scale to millions of data points .
Explanation
• geoplotlib provides implementations of dot maps, kernel density estimation, spatial graphs,
Voronoi tesselation, shapefiles.
• It supports a variety of maps like area maps, heat map, and point density maps.
• It works on maps, the common input is Latitude as lat and Longitude as lon.
Some of the modules are:
• geoplotlib module
• geoplotlib.layers module
• geoplotlib.utils module
• geoplotlib.core module
• geoplotlib.colors module
Types of Visualizations
1. Dot map: These maps are a simple representation of absolute and relative locations of
the objects/places.
• Density of the points directly maps to the density of objects on geographical surfaces.
Dot chart graph
Types
2.2D Histograms:Dot maps for density visualization can be hard and
therefore 2D histograms is a more direct way to compute the density.
• The approximation of density is visualized using a color scale.
• Bin size refers to the number of pixels of the histogram bins.
2D Histogram graph
Types
3.Heat map:
• The main drawback of histogram method is that it creates dependance on the bin size
and offset.
• For a smoother approximation a kernel density estimator approximates the true density
applying kernel functions in a window around each point.
• The window size depends on the bandwidth parameter.
• Smaller the bw value, more detailed but also noise estimation while larger the value
less detailed but smoother estimation.
Heat map graph
Types
4. Spatial graph: These graphs have well-defined spatial configurations.
One of the applications of it would be to show transport networks which
have been shown below.
Spatial graph
Types
5.Moving Points:
One another interesting application of geoplotlib is to see the
movements of the objects.

You might also like