บทนำ
Bokeh: แพ็กเกจ Visualization โค้ดเปิด ใช้ HTML/JavaScript เหมาะกับ Web Dashboard แปลงข้อมูลเป็น JSON สำหรับ BokehJS รันบน Browser สร้างกราฟโต้ตอบ ฝังใน Flask/Django/Jupyter ได้
Dependencies & Installation
Numpy, Pillow, Jinja2, Packaging, Pyyaml, Six, Tornado, Python-dateutil pip3 install bokeh conda install bokeh
Arbitrary Rectangles
วาดสี่เหลี่ยมผืนผ้าผืนตามตำแหน่งศูนย์กลาง ความสูง ความกว้าง และมุมเอียง ใช้ฟังก์ชัน rect
ตัวอย่าง
from math import pi
from bokeh.plotting import figure, output_file, show
output_file('rectanglesRandom.html')
p = figure(plot_width=400, plot_height=400)
p.rect(x=[1, 3, 5, 7], y=[1, 3, 5, 7], width=0.2, height=50, color="#CAB2D6", angle=pi/3, height_units="screen")
show(p)
ผลลัพธ์

คำอธิบาย
- นำเข้าแพ็กเกจและตั้งชื่อย่อ
- สร้าง Figure กำหนดขนาด
output_fileกำหนดไฟล์ HTML output- ใช้
rectวาดสี่เหลี่ยมหมุน ระบุ x, y (center), width, height, angle, height_units="screen" showแสดงผล