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

วิธีสร้าง Line Graph ด้วย Bokeh ใน Python

บทนำ

Line Graph แสดงแนวโน้มข้อมูลต่อเนื่อง Bokeh ทำให้โต้ตอบได้ (zoom, pan, hover)

การติดตั้ง

pip3 install bokeh
conda install bokeh

Dependencies

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

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

from bokeh.plotting import figure, output_file, show

x = [7, 3, 5, 9, 2, 0]
y = [2, 5, 8, 1, 2, 4]
output_file('sample.html')
fig = figure(title='Line plot', x_axis_label='x', y_axis_label='y')
fig.line(x, y)
show(fig)

คำอธิบาย

  • กำหนดข้อมูล x, y เป็นลิสต์

  • ใช้ figure ตั้งค่า title และ axis label

  • เรียก line(x, y) เพื่อพลอตเส้น