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

การวาด Axis-Aligned Rectangles (Quads) ด้วย Bokeh


บทนำ

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

Quads (Axis-Aligned Rectangles)

เรียกว่า Quads วาดโดยระบุ left, right, top, bottom ด้วยฟังก์ชัน quad (glyph function)

ตัวอย่าง

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)

ผลลัพธ์

การวาด Axis-Aligned Rectangles (Quads) ด้วย Bokeh

คำอธิบาย

  • นำเข้าแพ็กเกจและตั้งชื่อย่อ
  • สร้าง Figure กำหนดขนาด
  • output_file กำหนดไฟล์ HTML output
  • ใช้ quad วาดสี่เหลี่ยมจัตุรัสจับแกน ระบุ top, bottom, left, right arrays
  • show แสดงผล