Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Python

Trực quan hóa hình chữ nhật trục (axis-aligned rectangles) với Bokeh


Bokeh: package Python trực quan hóa, mã nguồn mở, render HTML/JS → dashboard web.

Chuyển data source thành JSON cho BokehJS (TypeScript) render browser.

Biểu đồ tương tác (interactive) khác Matplotlib/Seaborn (static). Nhúng Flask/Django/Jupyter.

Dependencies: NumPy, Pillow, Jinja2, Packaging, PyYAML, Six, Tornado, python-dateutil.

Cài đặt: pip3 install bokeh | conda install bokeh

Hình chữ nhật trục (quads) vẽ bằng quad() glyph function: chỉ định left, right, top, bottom.

Ví dụ

from bokeh.plotting import figure, output_file, show

output_file('alignedRect.html')
p = figure(plot_width=500, plot_height=300)
p.quad(top=[5, 8, 3, 0], bottom=[1, 2, 3, 9], left=[1, 2, 3, 9], right=[1.5, 2.2, 3.9], color="#B3DE69")
show(p)

Đầu ra

Trực quan hóa hình chữ nhật trục (axis-aligned rectangles) với Bokeh

Giải thích

  • Import Bokeh plotting.
  • figure() width/height.
  • output_file() file HTML.
  • quad() vẽ hình chữ nhật trục: top, bottom, left, right arrays, color.
  • show() hiển thị.