使用 Bokeh 在Python中绘制面积图
Bokeh是一个Python交互式数据可视化。与Matplotlib和Seaborn不同,Bokeh 使用 HTML 和 JavaScript 渲染其绘图。它针对现代 Web 浏览器进行演示,提供具有高性能交互性的新颖图形的优雅、简洁构造。
绘制面积图
面积图定义为两个系列之间共享一个公共区域的填充区域。 Bokeh Figure 类有两种方法,如下所示:
- 瓦雷亚()
- 哈雷亚()
1. varea() 方法: varea() 方法是一个垂直方向区域,它有一个 x 坐标数组和两个 y 坐标数组 y1 和 y2,它们之间将被填充。
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.
例子:
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)
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)
输出:
2. harea() 方法: harea() 方法是一个水平方向区域,它有一个 x 坐标数组和两个 y 坐标数组 y1 和 y2,它们之间将被填充。
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.
例子:
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)
输出: