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

วิธีสร้าง Scatter Plot ด้วย Bokeh ใน Python

บทนำ

Bokeh สร้าง Scatter Plot แบบโต้ตอบ ใช้งานง่าย เหมาะสำหรับแสดงความสัมพันธ์ระหว่างสองตัวแปร

การติดตั้ง

pip3 install bokeh
conda install bokeh

Dependencies

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

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

from bokeh.plotting import figure, output_file, show

fig = figure(plot_width=500, plot_height=400)
fig.scatter([1, 3, 7, 5, 4, 9], [6, 5, 9, 8, 0, 1], marker="circle", size=20, fill_color="grey")
output_file('scatterplot.html')
show(fig)

คำอธิบาย

  • ใช้ scatter ระบุ marker, size, color

  • บันทึกเป็น HTML และแสดงผล