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

Vẽ các hình dạng điểm dữ liệu (markers) khác nhau trong Bokeh

Bokeh hỗ trợ nhiều marker cho scatter plot: circle, circle_cross, circle_x, square, triangle, v.v.

Cài đặt

pip3 install bokeh
conda install bokeh

Ví dụ


from bokeh.plotting import figure, output_file, show

plot = figure(plot_width=300, plot_height=300)
plot.circle(x=[1, 4, 6], y=[3, 7, 8], size=20, fill_color='red')
plot.circle_cross(x=[2, 4, 5], y=[3, 8, 11], size=20, fill_color='black', fill_alpha=0.2, line_width=2)
plot.circle_x(x=[5, 3, 2], y=[2, 1, 7], size=20, fill_color='green', fill_alpha=0.6, line_width=2)
show(plot)

Kết quả

Vẽ các hình dạng điểm dữ liệu (markers) khác nhau trong Bokeh

Giải thích

  • Mỗi glyph vẽ một loạt điểm với cùng kiểu marker.
  • fill_alpha điều chỉnh độ trong suốt, line_width độ dày viền.

Danh sách marker phổ biến: circle, square, triangle, diamond, cross, x, asterisk, circle_cross, circle_x, square_cross, square_x.