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

วิธีแสดง Vertical Bar Graph ด้วย Bokeh และ Python

บทนำ

Bokeh รองรับ Vertical Bar Chart ผ่านเมธอด vbar ระบุ bottom, top, width, color ได้อย่างยืดหยุ่น

การติดตั้ง

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=400, plot_height=400)
fig.vbar(x=[2, 5, 9, 3], width=0.5, bottom=0, top=[2, 4, 6, 8], color="Cyan")
output_file('barplot.html')
show(fig)

คำอธิบาย

  • ใช้ vbar ระบุ x, top (ความสูง), bottom (ฐาน), width, color

  • เหมาะสำหรับกราฟแท่งตั้งตรงทั่วไป