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

Pyplot Histogram Bins ใน Matplotlib ถูกตีความอย่างไร?


เพื่อพลอท histogram bins ที่ตีความต่างกัน เราสามารถทำตามขั้นตอนดังนี้:

  • ตั้งค่าขนาดรูปและปรับ padding ระหว่างและรอบ subplots
  • สร้างลิสต์ข้อมูลสำหรับพลอทใน histogram
  • เพิ่ม subplot ลงในรูปปัจจุบัน nrows=1, ncols=3 และ index=1
  • พลอท histogram ด้วย data; bins เป็นตัวเลข
  • เพิ่ม subplot nrows=1, ncols=3 และ index=2
  • พลอท histogram ด้วย data; bins เป็นอาร์เรย์
  • เพิ่ม subplot nrows=1, ncols=3 และ index=3
  • พลอท histogram ด้วย data, bins เป็นสตริง

ตัวอย่าง

import matplotlib.pyplot as plt 
plt.rcParams["figure.figsize"] = [7.50, 3.50] 
plt.rcParams["figure.autolayout"] = True 
data = [1, 3, 1, 4, 7, 1, 3, 5, 4, 6, 5] 
plt.subplot(131) 
plt.hist(data, bins=len(data)) 
plt.subplot(132) 
plt.hist(data, bins=[1, 3, 5, 7]) 
plt.subplot(133) 
plt.hist(data, bins='stone') 
plt.show()

ผลลัพธ์

Pyplot Histogram Bins ใน Matplotlib ถูกตีความอย่างไร?