Plotting Different Types of Plots

Glyphs in Bokeh terminology means the basic building blocks of the Bokeh plots such as lines, rectangles, squares, etc. Bokeh plots are created using the bokeh.plotting interface which uses a default set of tools and styles.

Line Plot

Line charts are used to represent the relation between two data X and Y on a different axis. A line plot can be created using the line() method of the plotting module.

Syntax:

line(parameters)

Example:

Python3




# importing the modules 
from bokeh.plotting import figure, output_file, show 
  
# instantiating the figure object 
graph = figure(title = "Bokeh Line Graph"
  
# the points to be plotted 
x = [1, 2, 3, 4, 5
y = [5, 4, 3, 2, 1
  
# plotting the line graph 
graph.line(x, y) 
  
# displaying the model 
show(graph)


Output:

Refer to the below articles to get detailed information about the line plots.

Bar Plot

Bar plot or Bar chart is a graph that represents the category of data with rectangular bars with lengths and heights that is proportional to the values which they represent. It can be of two types horizontal bars and vertical bars. Each can be created using the hbar() and vbar() functions of the plotting interface respectively.

Syntax:

hbar(parameters)

vbar(parameters)

Example 1: Creating horizontal bars.

Python3




# importing the modules 
from bokeh.plotting import figure, output_file, show 
  
# instantiating the figure object 
graph = figure(title = "Bokeh Bar Graph"
  
# the points to be plotted 
x = [1, 2, 3, 4, 5
y = [1, 2, 3, 4, 5]  
  
# height / thickness of the plot
height = 0.5
  
# plotting the bar graph 
graph.hbar(x, right = y, height = height) 
  
# displaying the model 
show(graph)


Output:

Example 2: Creating the vertical bars

Python3




# importing the modules 
from bokeh.plotting import figure, output_file, show 
  
# instantiating the figure object 
graph = figure(title = "Bokeh Bar Graph"
  
# the points to be plotted 
x = [1, 2, 3, 4, 5
y = [1, 2, 3, 4, 5]  
  
# height / thickness of the plot
width = 0.5
  
# plotting the bar graph 
graph.vbar(x, top = y, width = width) 
  
# displaying the model 
show(graph)


Output:

Refer to the below articles to get detailed information about the bar charts.

Scatter Plot

A scatter plot is a set of dotted points to represent individual pieces of data in the horizontal and vertical axis. A graph in which the values of two variables are plotted along X-axis and Y-axis, the pattern of the resulting points reveals a correlation between them. It can be plotted using the scatter() method of the plotting module.

Syntax:

scatter(parameters)

Example:

Python3




# importing the modules 
from bokeh.plotting import figure, output_file, show 
from bokeh.palettes import magma 
import random 
  
      
# instantiating the figure object 
graph = figure(title = "Bokeh Scatter Graph"
  
# points to be plotted 
x = [n for n in range(256)] 
y = [random.random() + 1 for n in range(256)] 
  
  
# plotting the graph 
graph.scatter(x, y) 
  
# displaying the model 
show(graph)


Output:

Refer to the below articles to get detailed information about the scatter plots.

Patch Plot

Patch Plot shades a region of area to show a group having same properties. It can be created using the patch() method of the plotting module.

Syntax:

patch(parameters)

Example:

Python3




# importing the modules 
from bokeh.plotting import figure, output_file, show 
from bokeh.palettes import magma 
import random 
  
      
# instantiating the figure object 
graph = figure(title = "Bokeh Patch Plo"
  
# points to be plotted 
x = [n for n in range(256)] 
y = [random.random() + 1 for n in range(256)] 
  
# plotting the graph 
graph.patch(x, y) 
  
# displaying the model 
show(graph)


Output:

Refer to the below articles to get detailed information about the Patch Plot.

Area Plot

Area plots are defined as the filled regions between two series that share a common areas. Bokeh Figure class has two methods which are – varea(), harea()

Syntax:

varea(x, y1, y2, **kwargs)

harea(x1, x2, y, **kwargs)

Example 1: Creating vertical area plot

Python




# Implementation of bokeh function
import numpy as np 
from bokeh.plotting import figure, output_file, show 
      
x = [1, 2, 3, 4, 5
y1 = [2, 4, 5, 2, 4
y2 = [1, 2, 2, 3, 6
  
p = figure(plot_width=300, plot_height=300
  
# area plot 
p.varea(x=x, y1=y1, y2=y2,fill_color="green"
  
show(p)


Output:

Example 2: Creating horizontal area plot

Python3




# Implementation of bokeh function 
      
import numpy as np 
from bokeh.plotting import figure, output_file, show 
      
y = [1, 2, 3, 4, 5
x1 = [2, 4, 5, 2, 4
x2 = [1, 2, 2, 3, 6
  
p = figure(plot_width=300, plot_height=300
  
# area plot 
p.harea(x1=x1, x2=x2, y=y,fill_color="green"
  
show(p)


Output:

Refer to the below articles to get detailed information about the area charts

Pie Chart

Bokeh Does not provide a direct method to plot the Pie Chart. It can be created using the wedge() method. In the wedge() function, the primary parameters are the x and y coordinates of the wedge, the radius, the start_angle and the end_angle of the wedge. In order to plot the wedges in such a way that they look like a pie chart, the x, y, and radius parameters of all the wedges will be the same. We will only adjust the start_angle and the end_angle.

Syntax:

wedge(parameters)

Example: 

Python3




# importing the modules 
from bokeh.plotting import figure, output_file, show 
          
# instantiating the figure object 
graph = figure(title = "Bokeh Wedge Graph"
      
# the points to be plotted 
x = 0
y = 0
  
# radius of the wedge 
radius = 15
  
# start angle of the wedge 
start_angle = 1
  
# end angle of the wedge 
end_angle = 2
  
# plotting the graph 
graph.wedge(x, y, radius = radius, 
            start_angle = start_angle, 
            end_angle = end_angle) 
      
# displaying the model 
show(graph) 


Output:

Refer to the below articles to get detailed information about the pie charts.

Python Bokeh tutorial – Interactive Data Visualization with Bokeh

Python Bokeh is a Data Visualization library that provides interactive charts and plots. Bokeh renders its plots using HTML and JavaScript that uses modern web browsers for presenting elegant, concise construction of novel graphics with high-level interactivity. 

Features of Bokeh:

  • Flexibility: Bokeh can be used for common plotting requirements and for custom and complex use-cases.
  • Productivity: Its interaction with other popular Pydata tools (such as Pandas and Jupyter notebook) is very easy.
  • Interactivity: It creates interactive plots that change with the user interaction.
  • Powerful: Generation of visualizations for specialized use-cases can be done by adding JavaScript.
  • Shareable: Visual data are shareable. They can also be rendered in Jupyter notebooks.
  • Open source: Bokeh is an open-source project.

This tutorial aims at providing insight to Bokeh using well-explained concepts and examples with the help of a huge dataset. So let’s dive deep into the Bokeh and learn all it from basic to advance.

Table Of Content
 

  • Installation
  • Bokeh Interfaces – Basic Concepts of Bokeh
  • Getting Started
  • Annotations and Legends 
    • Customizing Legends 
       
  • Plotting Different Types of Plots 
    • Bar Plot
    • Scatter Plot
    • Patch Plot
    • Area Plot
    • Pie Chart
  • Creating Different Shapes 
    • Circle
    • Oval
    • Triangle
    • Rectangle
    • Polygon
  • Plotting Multiple Plots 
    • Vertical Layouts
    • Horizontal Layout
    • Grid Layout
  • Interactive Data Visualization 
    • Configuring Plot Tools
    • Interactive Legends
    • Adding Widgets to the Plot
  • Creating Different Types of Glyphs
  • Visualizing Different Types of Data
  • More Topics on Bokeh

Similar Reads

Installation

Bokeh is supported by CPython 3.6 and older with both standard distribution and anaconda distribution. Bokeh package has the following dependencies....

Bokeh Interfaces – Basic Concepts of Bokeh

Bokeh is simple to use as it provides a simple interface to the data scientists who do not want to be distracted by its implementation and also provides a detailed interface to developers and software engineers who may want more control over the Bokeh to create more sophisticated features. To do this Bokeh follows the layered approach....

Getting Started

After the installation and learning about the basic concepts of Bokeh let’s create a simple plot....

Annotations and Legends

...

Plotting Different Types of Plots

Annotations are the supplemental information such as titles, legends, arrows, etc that can be added to the graphs. In the above example, we have already seen how to add the titles to the graph. In this section, we will see about the legends....

Creating Different Shapes

...

Plotting Multiple Plots

...

Interactive Data Visualization

Glyphs in Bokeh terminology means the basic building blocks of the Bokeh plots such as lines, rectangles, squares, etc. Bokeh plots are created using the bokeh.plotting interface which uses a default set of tools and styles....

Creating Different Types of Glyphs

...

Visualizing Different Types of Data

...

More Topics on Bokeh

...