Bản đồ nhiệt trong python là gì?

Bản đồ nhiệt được định nghĩa là biểu diễn đồ họa của dữ liệu bằng cách sử dụng màu sắc để trực quan hóa giá trị của ma trận. Trong đó, để biểu thị các giá trị phổ biến hơn hoặc các hoạt động cao hơn, các màu sáng hơn về cơ bản là màu đỏ được sử dụng và để biểu thị các giá trị hoạt động hoặc ít phổ biến hơn, các màu tối hơn được ưu tiên. Bản đồ nhiệt cũng được xác định theo tên của ma trận bóng. Bản đồ nhiệt trong Seaborn có thể được vẽ bằng cách sử dụng seaborn. chức năng bản đồ nhiệt []

sinh ra biển. bản đồ nhiệt[]

cú pháp. sinh ra biển. bản đồ nhiệt[data, *, vmin=None, vmax=None, cmap=None, center=None, annot_kws=None, linewidths=0, linecolor=’white’, cbar=True, **kwargs]

Thông số quan trọng

  • dữ liệu. Tập dữ liệu 2D có thể được ép thành một ndarray
  • vmin, vmax. Các giá trị để neo bản đồ màu, nếu không chúng được suy ra từ dữ liệu và các đối số từ khóa khác
  • cmap. Ánh xạ từ các giá trị dữ liệu sang không gian màu
  • trung tâm. Giá trị để căn giữa bản đồ màu khi vẽ dữ liệu phân kỳ
  • chú thích. Nếu Đúng, hãy ghi giá trị dữ liệu vào từng ô
  • fmt. Mã định dạng chuỗi để sử dụng khi thêm chú thích
  • băng thông đường truyền. Chiều rộng của các dòng sẽ phân chia từng ô
  • màu đường kẻ. Màu của các đường sẽ phân chia từng ô
  • xà đơn. Có nên vẽ một thanh màu không

Tất cả các tham số ngoại trừ dữ liệu là tùy chọn

trả lại. Một đối tượng kiểu matplotlib. trục. _subplots. Trục Subplot

Hãy để chúng tôi hiểu bản đồ nhiệt với các ví dụ

Bản đồ nhiệt cơ bản

Tạo bản đồ nhiệt với các tham số mặc định. Chúng tôi sẽ tạo dữ liệu 10×10 2-D bằng cách sử dụng hàm randint[] của mô-đun NumPy

Python3




# importing the modules

import numpy as np

import seaborn as sn

import matplotlib.pyplot as plt

________số 8

# generating 2-D 10x10 matrix of random numbers

# importing the modules0

# importing the modules1# importing the modules2 # importing the modules3# importing the modules2 # importing the modules5# importing the modules6

# importing the modules7# importing the modules8# importing the modules2 import0# importing the modules6

# importing the modules7__import3# importing the modules2 import5import6# importing the modules6import6import9

numpy as np0import5numpy as np2numpy as np3

numpy as np0numpy as np5

________số 8

numpy as np7

numpy as np8# importing the modules2 import0# importing the modules2 import2

________số 8

import4

import5

đầu ra

The data to be plotted:

[[46 30 55 86 42 94 31 56 21  7]
[68 42 95 28 93 13 90 27 14 65]
[73 84 92 66 16 15 57 36 46 84]
[ 7 11 41 37  8 41 96 53 51 72]
[52 64  1 80 33 30 91 80 28 88]
[19 93 64 23 72 15 39 35 62  3]
[51 45 51 17 83 37 81 31 62 10]
[ 9 28 30 47 73 96 10 43 30  2]
[74 28 34 26  2 70 82 53 97 96]
[86 13 60 51 95 26 22 29 14 29]]

Chúng tôi sẽ sử dụng cùng một dữ liệu này trong tất cả các ví dụ

Neo bản đồ màu

Nếu chúng ta đặt giá trị vmin là 30 và giá trị vmax là 70 thì chỉ những ô có giá trị từ 30 đến 70 mới được hiển thị. Điều này được gọi là neo bản đồ màu

Python3




# importing the modules

import numpy as np

import seaborn as sn

import matplotlib.pyplot as plt

________số 8

# generating 2-D 10x10 matrix of random numbers

# importing the modules0

# importing the modules1# importing the modules2 # importing the modules3# importing the modules2# importing the modules5# importing the modules6

# importing the modules7__# importing the modules8# importing the modules2import0# importing the modules6

# importing the modules7__import3# importing the modules2import5import6# importing the modules6import6import9

________số 8

matplotlib.pyplot as plt6

matplotlib.pyplot as plt7____12 matplotlib.pyplot as plt9

 0# importing the modules2  2

________số 8

numpy as np7

numpy as np8# importing the modules2 import0# importing the modules2 9

# generating 2-D 10x10 matrix of random numbers0matplotlib.pyplot as plt7____12# generating 2-D 10x10 matrix of random numbers3

# generating 2-D 10x10 matrix of random numbers0 0# importing the modules2# generating 2-D 10x10 matrix of random numbers7

________số 8

import4

import5

đầu ra

Chọn bản đồ màu

Trong phần này, chúng ta sẽ xem xét tham số cmap. Matplotlib cung cấp cho chúng ta nhiều bản đồ màu, bạn có thể xem tất cả chúng tại đây. Trong ví dụ của chúng tôi, chúng tôi sẽ sử dụng tab20

Python3




# importing the modules

import numpy as np

import seaborn as sn

import matplotlib.pyplot as plt

________số 8

# generating 2-D 10x10 matrix of random numbers

# importing the modules0

# importing the modules1# importing the modules2 # importing the modules3# importing the modules2# importing the modules5# importing the modules6

# importing the modules7__# importing the modules8# importing the modules2import0# importing the modules6

# importing the modules7__import3# importing the modules2import5import6# importing the modules6import6import9

________số 8

matplotlib.pyplot as plt6

# importing the modules32# importing the modules2 # importing the modules34

________số 8

numpy as np7

numpy as np8# importing the modules2 import0# importing the modules2 9

# generating 2-D 10x10 matrix of random numbers0# importing the modules32# importing the modules2# importing the modules45

________số 8

import4

import5

đầu ra

Định tâm bản đồ màu

Định tâm cmap thành 0 bằng cách chuyển tham số trung tâm là 0

Python3




# importing the modules

import numpy as np

import seaborn as sn

import matplotlib.pyplot as plt

________số 8

# generating 2-D 10x10 matrix of random numbers

# importing the modules0

# importing the modules1# importing the modules2 # importing the modules3# importing the modules2# importing the modules5# importing the modules6

# importing the modules7__# importing the modules8# importing the modules2import0# importing the modules6

# importing the modules7__import3# importing the modules2import5import6# importing the modules6import6import9

________số 8

matplotlib.pyplot as plt6

# importing the modules32# importing the modules2 # importing the modules34

________ 183 ________ 12 ________ 185

________số 8

numpy as np7

numpy as np8# importing the modules2 import0# importing the modules2 9

# generating 2-D 10x10 matrix of random numbers0# importing the modules32# importing the modules2# importing the modules96

# generating 2-D 10x10 matrix of random numbers0# importing the modules83____12import00

________số 8

import4

import5

đầu ra

Hiển thị các giá trị ô

Nếu muốn hiển thị giá trị của các ô thì ta truyền tham số annot là True. fmt được sử dụng để chọn kiểu dữ liệu của nội dung của các ô được hiển thị.  

Python3




# importing the modules

import numpy as np

import seaborn as sn

import matplotlib.pyplot as plt

________số 8

# generating 2-D 10x10 matrix of random numbers

# importing the modules0

# importing the modules1# importing the modules2 # importing the modules3# importing the modules2# importing the modules5# importing the modules6

# importing the modules7__# importing the modules8# importing the modules2import0# importing the modules6

# importing the modules7__import3# importing the modules2import5import6# importing the modules6import6import9

________số 8

matplotlib.pyplot as plt6

import35# importing the modules2 import37

________số 8

numpy as np7

numpy as np8# importing the modules2 import0# importing the modules2 9

# generating 2-D 10x10 matrix of random numbers0import35____12import48

________số 8

import4

import5

đầu ra

Tùy chỉnh đường phân cách

Chúng ta có thể thay đổi độ dày và màu sắc của các đường ngăn cách các ô bằng cách sử dụng các tham số linewidths và linecolor tương ứng

Python3




# importing the modules

import numpy as np

import seaborn as sn

import matplotlib.pyplot as plt

________số 8

# generating 2-D 10x10 matrix of random numbers

# importing the modules0

# importing the modules1# importing the modules2 # importing the modules3# importing the modules2# importing the modules5# importing the modules6

# importing the modules7__# importing the modules8# importing the modules2import0# importing the modules6

# importing the modules7__import3# importing the modules2import5import6# importing the modules6import6import9

________số 8

matplotlib.pyplot as plt6

import83# importing the modules2 import85

import86______12 import88

________số 8

numpy as np7

numpy as np8# importing the modules2 import0# importing the modules2 9

# generating 2-D 10x10 matrix of random numbers0import83____12import99

# generating 2-D 10x10 matrix of random numbers0import86# importing the modules2numpy as np03

________số 8

import4

import5

đầu ra

Ẩn thanh màu

Chúng tôi có thể tắt thanh màu bằng cách đặt tham số cbar thành Sai

Python3




# importing the modules

import numpy as np

import seaborn as sn

import matplotlib.pyplot as plt

________số 8

# generating 2-D 10x10 matrix of random numbers

# importing the modules0

# importing the modules1# importing the modules2 # importing the modules3# importing the modules2# importing the modules5# importing the modules6

# importing the modules7__# importing the modules8# importing the modules2import0# importing the modules6

# importing the modules7__import3# importing the modules2import5import6# importing the modules6import6import9

________số 8

matplotlib.pyplot as plt6

numpy as np38# importing the modules2 numpy as np40

________số 8

numpy as np7

numpy as np8# importing the modules2 import0# importing the modules2 9

# generating 2-D 10x10 matrix of random numbers0numpy as np38____12numpy as np51

________số 8

import4

import5

đầu ra

Loại bỏ các nhãn

Chúng ta có thể vô hiệu hóa nhãn x và nhãn y bằng cách chuyển Sai trong các tham số xticklabels và yticklabels tương ứng

Bản đồ nhiệt được sử dụng để làm gì?

Theo định nghĩa, Bản đồ nhiệt là biểu diễn đồ họa của dữ liệu sử dụng hệ thống mã màu. Mục đích chính của Bản đồ nhiệt là để trực quan hóa rõ hơn số lượng vị trí/sự kiện trong tập dữ liệu và hỗ trợ hướng người xem đến các khu vực trực quan hóa dữ liệu quan trọng nhất . Nhưng chúng còn hơn thế nữa.

Bản đồ nhiệt có nghĩa là gì?

Bản đồ nhiệt [hoặc bản đồ nhiệt] là biểu diễn đồ họa của dữ liệu trong đó các giá trị được mô tả bằng màu sắc . Chúng rất cần thiết trong việc phát hiện những gì hoạt động hoặc không hoạt động trên trang web hoặc trang sản phẩm.

Bản đồ nhiệt là gì và nó hoạt động như thế nào?

Bản đồ nhiệt hoạt động bằng cách thu thập dữ liệu từ một trang web . Nó sử dụng thang màu từ tối đến sáng để hiển thị nội dung nào của trang web được nhấp nhiều hơn hoặc khu vực nào được chú ý nhiều hơn. Ví dụ: khu vực mà người xem nhấp vào nhiều nhất có màu tối và màu sáng nơi người xem không chú ý.

Bản đồ nhiệt nên được sử dụng ở đâu?

Khi nào bạn nên sử dụng bản đồ nhiệt. Bản đồ nhiệt được sử dụng để hiển thị mối quan hệ giữa hai biến, một biến được vẽ trên mỗi trục . Bằng cách quan sát cách màu ô thay đổi trên mỗi trục, bạn có thể quan sát xem có bất kỳ mẫu nào có giá trị cho một hoặc cả hai biến hay không.

Chủ Đề