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

Vertical Histogram ใน Python และ Matplotlib

การพล็อต Histogram แนวตั้ง (Vertical)

Histogram แนวตั้งเป็นค่าเริ่มต้นของ plt.hist() ใช้ parameter orientation="vertical"

ขั้นตอนหลัก

  • ตั้งค่าขนาดรูปและ padding
  • สร้างรายการข้อมูล x
  • พล็อต histogram ด้วย plt.hist(x, orientation="vertical")
  • แสดงผลด้วย show()

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

import matplotlib.pyplot as plt

plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True

x = [1, 2, 3, 1, 2, 3, 4, 1, 3, 4, 5]
plt.hist(x, orientation="vertical")
plt.show()

คำอธิบาย

orientation="vertical" เป็นค่าเริ่มต้น สามารถเปลี่ยนเป็น "horizontal" ได้