数据不知道如何可视化?一款工具推荐给大家
bigegpt 2024-08-10 12:16 9 浏览
之前我们介绍过 Python 里面的一些数据分析和可视化工具,比如 Pandas、Modin、Dash 等。今天要介绍一款标星 12.1K 的数据可视化工具 bokeh,优雅、简洁、高性能的交互式可视化库,同时支持大数据量和流式数据。其中 PyPI 和 Conda 每月安装超过 10万+,可见 bokeh 非常受欢迎。
安装方式很简单:pip install bokeh,接下来我们介绍几个示例看一下 bokeh 的使用。
- 曲线/折线图曲线/折线图日常用的比较多,能够用来直接看一些数据增长趋势,比如数学里面比较典型的几个表示趋势的函数如下:通过差不多 20 行代码就能实现上图的效果。
- 点状染色图这种类型的图可以分析很多的东西,通过色彩、点的大小的不同,但是我每次都觉得非常炫酷,至于能不能直观的看出什么我并不在意,就是那么任性。
import numpy as np
from bokeh.plotting import figure, output_file, show
# prepare some data
N = 4000
x = np.random.random(size=N) * 100
y = np.random.random(size=N) * 100
radii = np.random.random(size=N) * 1.5
colors = [
"#%02x%02x%02x" % (int(r), int(g), 150) for r, g in zip(50+2*x, 30+2*y)
]
# output to static HTML file (with CDN resources)
output_file("color_scatter.html", title="color_scatter.py example", mode="cdn")
TOOLS = "crosshair,pan,wheel_zoom,box_zoom,reset,box_select,lasso_select"
# create a new plot with the tools above, and explicit ranges
p = figure(tools=TOOLS, x_range=(0, 100), y_range=(0, 100))
# add a circle renderer with vectorized colors and sizes
p.circle(x, y, radius=radii, fill_color=colors, fill_alpha=0.6, line_color=None)
# show the resultsshow(p)