Hướng dẫn bins python - trăn thùng

Một biểu đồ đơn giản có thể là bước đầu tiên tuyệt vời trong việc tìm hiểu một bộ dữ liệu. Trước đó, chúng tôi đã thấy một bản xem trước của hàm biểu đồ của Matplotlib (xem so sánh, mặt nạ và logic boolean), tạo ra một biểu đồ cơ bản trong một dòng, một khi nhập khẩu nồi hơi bình thường được thực hiện:

Nội dung chính

  • Biểu đồ hai chiều và Binnings¶
  • plt.hist(data, bins=30, normed=True, alpha=0.5, histtype='stepfilled', color='steelblue', edgecolor='none'); 6: Biểu đồ hai chiều
  • x1 = np.random.normal(0, 0.8, 1000) x2 = np.random.normal(-2, 1, 1000) x3 = np.random.normal(3, 2, 1000) kwargs = dict(histtype='stepfilled', alpha=0.3, normed=True, bins=40) plt.hist(x1, **kwargs) plt.hist(x2, **kwargs) plt.hist(x3, **kwargs); 5: Binnings lục giác
  • Ước tính mật độ hạt nhân
  • Làm thế nào để bạn thêm thùng vào biểu đồ trong Python?
  • Làm thế nào để bạn làm thùng cho một biểu đồ?
  • BIN trong biểu đồ Python là gì?

In [1]:

%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
plt.style.use('seaborn-white')

data = np.random.randn(1000)

Hàm

plt.hist(data, bins=30, normed=True, alpha=0.5,
         histtype='stepfilled', color='steelblue',
         edgecolor='none');
7 có nhiều tùy chọn để điều chỉnh cả tính toán và màn hình; Dưới đây là một ví dụ về biểu đồ tùy chỉnh hơn:

In [3]:

plt.hist(data, bins=30, normed=True, alpha=0.5,
         histtype='stepfilled', color='steelblue',
         edgecolor='none');

DocString

plt.hist(data, bins=30, normed=True, alpha=0.5,
         histtype='stepfilled', color='steelblue',
         edgecolor='none');
0 có nhiều thông tin hơn về các tùy chọn tùy chỉnh khác có sẵn. Tôi thấy sự kết hợp này của
plt.hist(data, bins=30, normed=True, alpha=0.5,
         histtype='stepfilled', color='steelblue',
         edgecolor='none');
1 cùng với một số minh bạch
plt.hist(data, bins=30, normed=True, alpha=0.5,
         histtype='stepfilled', color='steelblue',
         edgecolor='none');
2 rất hữu ích khi so sánh biểu đồ của một số phân phối:

In [4]:

x1 = np.random.normal(0, 0.8, 1000)
x2 = np.random.normal(-2, 1, 1000)
x3 = np.random.normal(3, 2, 1000)

kwargs = dict(histtype='stepfilled', alpha=0.3, normed=True, bins=40)

plt.hist(x1, **kwargs)
plt.hist(x2, **kwargs)
plt.hist(x3, **kwargs);

Nếu bạn chỉ muốn tính toán biểu đồ (nghĩa là đếm số lượng điểm trong một thùng nhất định) và không hiển thị nó, hàm

plt.hist(data, bins=30, normed=True, alpha=0.5,
         histtype='stepfilled', color='steelblue',
         edgecolor='none');
3 có sẵn:

In [5]:

counts, bin_edges = np.histogram(data, bins=5)
print(counts)

Biểu đồ hai chiều và Binnings¶

plt.hist(data, bins=30, normed=True, alpha=0.5, histtype='stepfilled', color='steelblue', edgecolor='none'); 6: Biểu đồ hai chiều

In [6]:

mean = [0, 0]
cov = [[1, 1], [1, 2]]
x, y = np.random.multivariate_normal(mean, cov, 10000).T

plt.hist(data, bins=30, normed=True, alpha=0.5, histtype='stepfilled', color='steelblue', edgecolor='none'); 6: Biểu đồ hai chiều

x1 = np.random.normal(0, 0.8, 1000) x2 = np.random.normal(-2, 1, 1000) x3 = np.random.normal(3, 2, 1000) kwargs = dict(histtype='stepfilled', alpha=0.3, normed=True, bins=40) plt.hist(x1, **kwargs) plt.hist(x2, **kwargs) plt.hist(x3, **kwargs); 5: Binnings lục giác

Ước tính mật độ hạt nhân

In [12]:

plt.hist(data, bins=30, normed=True, alpha=0.5,
         histtype='stepfilled', color='steelblue',
         edgecolor='none');
0

Làm thế nào để bạn thêm thùng vào biểu đồ trong Python?

Làm thế nào để bạn làm thùng cho một biểu đồ?

In [8]:

plt.hist(data, bins=30, normed=True, alpha=0.5,
         histtype='stepfilled', color='steelblue',
         edgecolor='none');
7

BIN trong biểu đồ Python là gì?

x1 = np.random.normal(0, 0.8, 1000)
x2 = np.random.normal(-2, 1, 1000)
x3 = np.random.normal(3, 2, 1000)

kwargs = dict(histtype='stepfilled', alpha=0.3, normed=True, bins=40)

plt.hist(x1, **kwargs)
plt.hist(x2, **kwargs)
plt.hist(x3, **kwargs);
4.

x1 = np.random.normal(0, 0.8, 1000) x2 = np.random.normal(-2, 1, 1000) x3 = np.random.normal(3, 2, 1000) kwargs = dict(histtype='stepfilled', alpha=0.3, normed=True, bins=40) plt.hist(x1, **kwargs) plt.hist(x2, **kwargs) plt.hist(x3, **kwargs); 5: Binnings lục giác

Ước tính mật độ hạt nhân

Làm thế nào để bạn thêm thùng vào biểu đồ trong Python?

In [9]:

Làm thế nào để bạn làm thùng cho một biểu đồ?

Ước tính mật độ hạt nhân

Làm thế nào để bạn thêm thùng vào biểu đồ trong Python?

Làm thế nào để bạn làm thùng cho một biểu đồ?

In [10]:

plt.hist(data, bins=30, normed=True, alpha=0.5,
         histtype='stepfilled', color='steelblue',
         edgecolor='none');
3

BIN trong biểu đồ Python là gì?

Hàm
plt.hist(data, bins=30, normed=True, alpha=0.5,
         histtype='stepfilled', color='steelblue',
         edgecolor='none');
7 có nhiều tùy chọn để điều chỉnh cả tính toán và màn hình; Dưới đây là một ví dụ về biểu đồ tùy chỉnh hơn:

DocString

plt.hist(data, bins=30, normed=True, alpha=0.5,
         histtype='stepfilled', color='steelblue',
         edgecolor='none');
0 có nhiều thông tin hơn về các tùy chọn tùy chỉnh khác có sẵn. Tôi thấy sự kết hợp này của
plt.hist(data, bins=30, normed=True, alpha=0.5,
         histtype='stepfilled', color='steelblue',
         edgecolor='none');
1 cùng với một số minh bạch
plt.hist(data, bins=30, normed=True, alpha=0.5,
         histtype='stepfilled', color='steelblue',
         edgecolor='none');
2 rất hữu ích khi so sánh biểu đồ của một số phân phối:

Làm thế nào để bạn thêm thùng vào biểu đồ trong Python?

Làm thế nào để bạn làm thùng cho một biểu đồ?.

Phương pháp 1: Chỉ định số lượng thùng PLT. Lịch sử (dữ liệu, thùng = 6).

Phương pháp 2: Chỉ định ranh giới thùng PLT. Lịch sử (dữ liệu, thùng = [0, 4, 8, 12, 16, 20]).

Phương pháp 3: Chỉ định chiều rộng bin w = 2 plt. Lịch sử (dữ liệu, thùng = np. Arange (min (dữ liệu), tối đa (dữ liệu) + w, w)).

Làm thế nào để bạn làm thùng cho một biểu đồ?

Có một vài quy tắc chung để chọn thùng:...

BIN nên có cùng kích thước.....

Các thùng nên bao gồm tất cả các dữ liệu, thậm chí các ngoại lệ.....

Ranh giới cho các thùng phải hạ cánh ở số lượng toàn bộ bất cứ khi nào có thể (điều này làm cho biểu đồ dễ đọc hơn) ..

Chọn từ 5 đến 20 thùng ..

BIN trong biểu đồ Python là gì?

Nó là một loại biểu đồ thanh.Để xây dựng một biểu đồ, bước đầu tiên là về Bin bin, phạm vi của các giá trị - nghĩa là chia toàn bộ phạm vi giá trị thành một loạt các khoảng - và sau đó đếm số lượng giá trị rơi vào mỗi khoảng.Các thùng thường được chỉ định là các khoảng liên tiếp, không chồng chéo của một biến.divide the entire range of values into a series of intervals — and then count how many values fall into each interval. The bins are usually specified as consecutive, non-overlapping intervals of a variable.divide the entire range of values into a series of intervals — and then count how many values fall into each interval. The bins are usually specified as consecutive, non-overlapping intervals of a variable.