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

Cách tạo histogram logarit trong Python

Để tạo histogram logarit, dùng log=True trong tham số hist().

Các bước

  • Tạo danh sách số.
  • Vẽ histogram với density=True.
  • Hiển thị bằng show().

Ví dụ

import numpy as np
import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
k = np.array([5, 5, 5, 5])
x, bins, p = plt.hist(np.log(k), density=True, log=True)
plt.show()

Kết quả

Cách tạo histogram logarit trong Python