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

Tạo Step line plot (đồ thị bậc thang) với Bokeh


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

Tương thích NumPy, Pandas. Tạo biểu đồ tương tác, dashboard.

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

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

Hàm step() trong glyph functions vẽ dữ liệu rời rạc dạng bậc thang.

Ví dụ

from bokeh.plotting import figure, output_file, show

output_file("stepLine.html")
p = figure(plot_width=500, plot_height=300)
p.step([2, 5, 3, 6, 7, 9], [6, 3, 2, 1, 0, 5], line_width=2, mode="center")
show(p)

Đầu ra

Tạo Step line plot (đồ thị bậc thang) với Bokeh

Giải thích

  • Import Bokeh plotting.
  • figure() với width/height.
  • output_file() chỉ định file HTML.
  • step() vẽ step line: x=[2,5,3,6,7,9], y=[6,3,2,1,0,5], line_width=2, mode="center".
  • show() hiển thị.