0

0

使用 Python Bokeh 创建具有多个字形的绘图

WBOY

WBOY

发布时间:2023-09-02 17:49:01

|

1586人浏览过

|

来源于tutorialspoint

转载

bokeh is a powerful data visualization library in python that helps to create interactive and unique visualizations for the web. bokeh supports various rendering techniques and provides a wide range of built-in tools for creating complex visualizations with multiple glyphs. this document will guide you through the process of creating a plot with multiple glyphs using bokeh. this plot combines different glyphs to display multiple data series in a single plot that provides a more efficient way to understand the relationship between different variables.

什么是字形(Glyphs),它们的主要优势是什么?

Glyphs are graphical representations of characters, symbols, or icons used in typography and graphic design. They are often used in the design and layout of text, and can include letters, numbers, punctuation marks, and other symbols.

使用字形的一些关键优势包括−

  • 提高可读性− 字形可以被设计得非常易读,使读者能够更快速、准确地理解文本。

  • 增强美观度 − 字形可以用来为文本添加视觉趣味和吸引力,使其更具视觉吸引力和互动性。

    立即学习Python免费学习笔记(深入)”;

  • 一致性和准确性 − 字形可以设计成大小、形状和风格一致,确保文本易于阅读和视觉上连贯。

  • Flexibility − Glyphs can be scaled and modified easily, making it possible to use them in a wide range of contexts and applications.

  • 国际化 − 字形可以用来表示各种语言和书写系统的字符和符号,使其在国际化和本地化方面非常有用。

Overall, glyphs are a powerful tool for typography and graphic design, and can help improve the legibility, aesthetics, consistency, and flexibility of text.

Statistical Significance of these

Glyphs themselves are not subject to statistical significance tests since they are not statistical data. However, the use of glyphs in typography and graphic design may be subject to statistical significance tests if they are used in the context of an experiment or study that involves statistical analysis. For example, if a study is examining the effects of different fonts on reading speed or comprehension, statistical tests may be used to determine whether any observed differences between the fonts are statistically significant.

In general, statistical significance tests are used to determine whether observed differences or effects are likely to be due to chance or random variation, or whether they are likely to reflect a true difference or effect in the population being studied. The specific test used depends on the research question, the type of data being analyzed, and the assumptions made about the data and population.

Therefore, while glyphs themselves are not subject to statistical significance tests, they may be used in the context of experiments or studies that are subject to statistical analysis to determine whether any observed differences or effects are statistically significant.

Prerequisites

Before we dive into the task few things should is expected to be installed onto your system −

List of recommended settings −

Avactis购物车
Avactis购物车

Avactis是一个强大的PHP在线购物系统拥有多个版本包括开源版本。它具备一个在线购物系统所需要的所有功能从产品到会员管理,订单和营销。可以无限分类和为产品指定任务数量的图片(支持自动生成缩略图)。使用自定义字段功能,让你可以更好地定义一个产品。该系统提供以非常灵活的方式来创建任意类型的促销活动如设置折扣代码,基于价格的折扣或基于数量的折扣等。

下载
  • pip install pandas, bokeh

  • It is expected that the user will have access to any standalone IDE such as VS-Code, PyCharm, Atom or Sublime text.

  • Even online Python compilers can also be used such as Kaggle.com, Google Cloud platform or any other will do.

  • Updated version of Python. At the time of writing the article I have used 3.10.9 version.

  • 使用Jupyter notebook的知识。

  • 了解和应用虚拟环境将会有益,但不是必需的。

  • 同时,预期该人员对统计学和数学有很好的理解。

创建基本图表

To create a plot, we first need to import the necessary modules, such as `Figure`, `ColumnDataSource`, and the desired glyphs. Here's an example code snippet that creates a line plot with a single glyph using Bokeh −

Syntax

from bokeh.plotting import figure, output_file, show
output_file("line.html")
p = figure(title="Line Plot", x_axis_label="X", y_axis_label="Y")

x = [1, 2, 3, 4, 5]
y = [6, 7, 2, 4, 5]

p.line(x, y, line_width=2)

show(p)

Output

使用 Python Bokeh 创建具有多个字形的绘图

This code will create a line plot with x-axis labeled as "X", y-axis labeled as "Y", and a title "Line Plot". The line plot will display five data points with their corresponding x and y values.

将多个字形添加到图表中

To add multiple glyphs to the plot, we need to use the `Figure` object's `multi_line()` function. The `multi_line()` function takes multiple sequences of x and y values and creates a line glyph for each of them. Here's an example code snippet to create a line plot with multiple glyphs −

from bokeh.plotting import figure, output_file, show
from bokeh.models import ColumnDataSource

output_file("multi_line.html")

p = figure(title="Multiple Glyphs", x_axis_label="X", y_axis_label="Y")

x1 = [1, 2, 3, 4, 5]
y1 = [6, 7, 2, 4, 5]

x2 = [1, 2, 3, 4, 5]
y2 = [2, 4, 6, 8, 10]

source = ColumnDataSource(data=dict(x1=x1, y1=y1, x2=x2, y2=y2))
p.multi_line(xs=[source.data["x1"], source.data["x2"]],
   ys=[source.data["y1"], source.data["y2"]],
   line_color=["red", "blue"], line_width=[2, 2])
show(p)

Output

使用 Python Bokeh 创建具有多个字形的绘图

Here, we created two sets of x and y values and stored them in a `ColumnDataSource` object. We then passed the two sequences of x and y values to the `multi_line()` function, along with the colors and line widths of the two glyphs. This will create a line plot with two glyphs, one in red color and one in blue color, each with their corresponding x and y values.

Final Program, Code

# Basic plot

from bokeh.plotting import figure, output_file, show
output_file("line.html")

p = figure(title="Line Plot", x_axis_label="X", y_axis_label="Y")

x = [1, 2, 3, 4, 5]
y = [6, 7, 2, 4, 5]

p.line(x, y, line_width=2)

show(p)

# Multiple graphs

from bokeh.plotting import figure, output_file, show
from bokeh.models import ColumnDataSource

output_file("multi_line.html")

p = figure(title="Multiple Glyphs", x_axis_label="X", y_axis_label="Y")

x1 = [1, 2, 3, 4, 5]
y1 = [6, 7, 2, 4, 5]

x2 = [1, 2, 3, 4, 5]
y2 = [2, 4, 6, 8, 10]

source = ColumnDataSource(data=dict(x1=x1, y1=y1, x2=x2, y2=y2))

p.multi_line(xs=[source.data["x1"], source.data["x2"]],
   ys=[source.data["y1"], source.data["y2"]],
   line_color=["red", "blue"], line_width=[2, 2])

show(p)

Conclusion

在本文档中,我们学习了如何使用Bokeh创建具有多个图元的图表。我们首先介绍了图元,然后使用单个图元创建了一个基本的折线图。然后,我们使用`Figure`对象的`multi_line()`函数向图表中添加了多个图元。使用Bokeh,可以轻松创建交互式可视化,帮助理解不同数据点之间的关系。Bokeh允许您以最小的努力创建美观的可视化,让您专注于分析数据,而不必担心可视化。

python速学教程(入门到精通)
python速学教程(入门到精通)

python怎么学习?python怎么入门?python在哪学?python怎么学才快?不用担心,这里为大家提供了python速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载

本站声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

相关专题

更多
PS使用蒙版相关教程
PS使用蒙版相关教程

本专题整合了ps使用蒙版相关教程,阅读专题下面的文章了解更多详细内容。

23

2026.01.19

java用途介绍
java用途介绍

本专题整合了java用途功能相关介绍,阅读专题下面的文章了解更多详细内容。

11

2026.01.19

java输出数组相关教程
java输出数组相关教程

本专题整合了java输出数组相关教程,阅读专题下面的文章了解更多详细内容。

3

2026.01.19

java接口相关教程
java接口相关教程

本专题整合了java接口相关内容,阅读专题下面的文章了解更多详细内容。

2

2026.01.19

xml格式相关教程
xml格式相关教程

本专题整合了xml格式相关教程汇总,阅读专题下面的文章了解更多详细内容。

4

2026.01.19

PHP WebSocket 实时通信开发
PHP WebSocket 实时通信开发

本专题系统讲解 PHP 在实时通信与长连接场景中的应用实践,涵盖 WebSocket 协议原理、服务端连接管理、消息推送机制、心跳检测、断线重连以及与前端的实时交互实现。通过聊天系统、实时通知等案例,帮助开发者掌握 使用 PHP 构建实时通信与推送服务的完整开发流程,适用于即时消息与高互动性应用场景。

13

2026.01.19

微信聊天记录删除恢复导出教程汇总
微信聊天记录删除恢复导出教程汇总

本专题整合了微信聊天记录相关教程大全,阅读专题下面的文章了解更多详细内容。

93

2026.01.18

高德地图升级方法汇总
高德地图升级方法汇总

本专题整合了高德地图升级相关教程,阅读专题下面的文章了解更多详细内容。

112

2026.01.16

全民K歌得高分教程大全
全民K歌得高分教程大全

本专题整合了全民K歌得高分技巧汇总,阅读专题下面的文章了解更多详细内容。

155

2026.01.16

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

相关下载

更多

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号