Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

วิธีแสดงจุดข้อมูล (Data Points) รูปทรงต่างๆ ด้วย Bokeh ใน Python

บทนำ

Bokeh ให้ Glyphs หลากหลายรูปทรงสำหรับ Scatter plots เช่น วงกลม, วงกลมขวาง, วงกลมครอส ช่วยสื่อสารข้อมูลเชิงปริมาณได้ชัดเจน

การติดตั้ง

pip3 install bokeh
conda install bokeh

Dependencies

Numpy, Pillow, Jinja2, Packaging, Pyyaml, Six, Tornado, Python-dateutil

ตัวอย่างโค้ด

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)

คำอธิบาย

  • circle: วงกลมทึบ

  • circle_cross: วงกลมพร้อมเครื่องหมาย +

  • circle_x: วงกลมพร้อมเครื่องหมาย x

  • รองรับ fill_alpha ความโปร่งใส และ line_width