Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Python

Histogram dọc (Vertical Histogram) trong Python và Matplotlib

Để vẽ histogram dọc trong Python và Matplotlib:

  • Thiết lập kích thước hình và điều chỉnh khoảng đệm subplot.
  • Tạo danh sách điểm dữ liệu.
  • Vẽ histogram với orientation="vertical".
  • Hiển thị hình bằng show().

Ví dụ

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()

Kết quả

Histogram dọc (Vertical Histogram) trong Python và Matplotlib