The Wayback Machine - https://web.archive.org/web/20240108170010/https://www.geeksforgeeks.org/make-an-area-plot-in-python-using-bokeh/
Open In App
Related Articles

Make an area plot in Python using Bokeh

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

Bokeh is a Python interactive data visualization. Unlike Matplotlib and Seaborn, Bokeh renders its plots using HTML and JavaScript. It targets modern web browsers for presentation providing elegant, concise construction of novel graphics with high-performance interactivity.

Plotting the Area Plots

Area plots are defined as the filled regions between two series that share a common areas. Bokeh Figure class has two methods which are given below:

  • varea()
  • harea()

1. varea() method:  varea() method is a vertical directed area which has one x coordinate array and two y coordinate arrays, y1 and y2, that will be filled between.

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

Parameter:This method accept the following parameters that are described below:

  • x: This parameter is the x-coordinates for the points of the area.
  • y1: This parameter is the y-coordinates for the points of one side of the area.
  • y2: This parameter is the y-coordinates for the points of other side of the area.

Example:

Python3




# 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]
   
output_file("geeksforgeeks.html")
   
p = figure(plot_width=300, plot_height=300)
   
# area plot
p.varea(x=x, y1=y1, y2=y2,fill_color="green")
   
show(p)


Output:

2. harea() method:  harea() method is a horizontal directed area which has one x coordinate array and two y coordinate arrays, y1 and y2, that will be filled between.

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

Parameter:This method accept the following parameters that are described below:

  • x1: This parameter is the x-coordinates for the points of one side of the area.
  • x2: This parameter is the x-coordinates for the points of other side of the area.
  • y: This parameter is the y-coordinates for the points of the area.

Example:

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]
   
output_file("geeksforgeeks.html")
   
p = figure(plot_width=300, plot_height=300)
   
# area plot
p.harea(x1=x1, x2=x2, y=y,fill_color="green")
   
show(p)


Output:


Don't miss your chance to ride the wave of the data revolution! Every industry is scaling new heights by tapping into the power of data. Sharpen your skills, become a part of the hottest trend in the 21st century.
Dive into the future of technology - explore the Complete Machine Learning and Data Science Program by GeeksforGeeks and stay ahead of the curve.

Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore.
Last Updated : 22 Jun, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads
Complete Tutorials