Python Bokeh – 在图形上绘制二次曲线
Bokeh 是一个Python交互式数据可视化。它使用 HTML 和 JavaScript 渲染其绘图。它针对现代 Web 浏览器进行演示,提供具有高性能交互性的新颖图形的优雅、简洁构造。
Bokeh 可用于在图形上绘制二次曲线。可以使用plotting
模块的quadratic()
方法在图形上绘制二次曲线。
plotting.figure.quadratic()
Syntax : quadratic(parameters)
Parameters :
- x0 : x-coordinates of the starting points of the quadratic
- y0 : y-coordinates of the starting points of the quadratic
- x1 : x-coordinates of the ending points of the quadratic
- y1 : y-coordinates of the ending points of the quadratic
- cx : x-coordinates of the control points of the quadratic
- cy : y-coordinates of the control points of the quadratic
Returns : an object of class GlyphRenderer
示例 1:在此示例中,我们将使用默认值来绘制图形。
# importing the modules
from bokeh.plotting import figure, output_file, show
# file to save the model
output_file("gfg.html")
# instantiating the figure object
graph = figure(title = "Bokeh Quadratic Graph")
# the points to be plotted
x0 = 1
y0 = 4
x1 = 5
y1 = 4
cx = 2.5
cy = 8
# plotting the graph
graph.quadratic(x0, y0,
x1, y1,
cx, cy)
# displaying the model
show(graph)
输出 :
示例 2:在此示例中,我们将绘制具有各种其他参数的多条二次曲线。
# importing the modules
from bokeh.plotting import figure, output_file, show
# file to save the model
output_file("gfg.html")
# instantiating the figure object
graph = figure(title = "Bokeh Quadratic Graph")
# name of the x-axis
graph.xaxis.axis_label = "x-axis"
# name of the y-axis
graph.yaxis.axis_label = "y-axis"
# points to be plotted
x0 = [1, 0, 0]
y0 = [4, 8, 5]
x1 = [5, 4, 4]
y1 = [4, 8, 7]
cx = [2.5, 2, 4]
cy = [8, 3, 4]
# line color value of the quadratic
line_color = ["yellow", "red", "purple"]
# line width value of the quadratic
line_width = [10, 5, 8]
# plotting the graph
graph.quadratic(x0, y0,
x1, y1,
cx, cy,
line_color = line_color,
line_width = line_width)
# displaying the model
show(graph)
输出 :
在评论中写代码?请使用 ide.geeksforgeeks.org,生成链接并在此处分享链接。