Harta termografica este definită ca o reprezentare grafică a datelor folosind culori pentru a vizualiza valoarea matricei. În aceasta, pentru a reprezenta valori mai obișnuite sau activități mai înalte se folosesc culori mai strălucitoare, practic, culori roșiatice și pentru a reprezenta valori mai puțin obișnuite sau de activitate, sunt preferate culorile mai închise. Harta termică este definită și de numele matricei de umbrire. Hărțile termice din Seaborn pot fi reprezentate grafic folosind funcția seaborn.heatmap().
seaborn.heatmap()
Sintaxă: seaborn.heatmap( date , * , vmin=Niciuna , vmax=Niciuna , cmap=Niciuna , centru=Niciuna , annot_kws=Nu , lățimi de linii=0 , linecolor=’alb’ , cbar=Adevărat , **kwargs )
Parametri importanți:
date: set de date 2D care poate fi forțat într-un ndarray. vmin, vmax: Valori pentru ancorarea hărții de culori, altfel sunt deduse din date și alte argumente ale cuvintelor cheie. cmap: maparea de la valorile datelor la spațiul de culoare. center: Valoarea la care să se centreze harta de culori la trasarea datelor divergente. annot: Dacă este adevărat, scrieți valoarea datelor în fiecare celulă. fmt: cod de formatare a șirurilor de folosit atunci când adăugați adnotări. linewidths: lățimea liniilor care vor împărți fiecare celulă. linecolor: culoarea liniilor care vor împărți fiecare celulă. cbar: Dacă se desenează o bară de culori.
Toți parametrii, cu excepția datelor, sunt opționali.
Se intoarce: Un obiect de tip matplotlib.axes._subplots.AxesSubplot
Să înțelegem harta termică cu exemple.
Hartă termică de bază
Realizarea unei hărți termice cu parametrii impliciti. Vom crea date 2-D de 10×10 folosind Data() funcția modulului NumPy.
Python3
# importing the modules> import> numpy as np> import> seaborn as sn> import> matplotlib.pyplot as plt> > # generating 2-D 10x10 matrix of random numbers> # from 1 to 100> data>=> np.random.randint(low>=> 1>,> >high>=> 100>,> >size>=> (>10>,>10>))> print>(>'The data to be plotted:
'>)> print>(data)> > # plotting the heatmap> hm>=> sn.heatmap(data>=> data)> > # displaying the plotted heatmap> plt.show()> |
>
>
Ieșire:
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]]>

Vom folosi aceleași date în toate exemplele.
Ancorarea hărții de culori
Dacă setăm min valoare la 30 și vmax valoarea la 70, atunci vor fi afișate numai celulele cu valori între 30 și 70. Aceasta se numește ancorarea hărții de culori.
Python3
# importing the modules> import> numpy as np> import> seaborn as sn> import> matplotlib.pyplot as plt> > # generating 2-D 10x10 matrix of random numbers> # from 1 to 100> data>=> np.random.randint(low>=>1>,> >high>=>100>,> >size>=>(>10>,>10>))> > # setting the parameter values> vmin>=> 30> vmax>=> 70> > # plotting the heatmap> hm>=> sn.heatmap(data>=>data,> >vmin>=>vmin,> >vmax>=>vmax)> > # displaying the plotted heatmap> plt.show()> |
>
>
Ieșire:

Alegerea hărții de culori
În aceasta, ne vom uita la cmap parametru. Matplotlib ne oferă mai multe hărți de culori, le puteți vedea pe toate Aici . În exemplul nostru, vom folosi fila20 .
Python3
# importing the modules> import> numpy as np> import> seaborn as sn> import> matplotlib.pyplot as plt> > # generating 2-D 10x10 matrix of random numbers> # from 1 to 100> data>=> np.random.randint(low>=>1>,> >high>=>100>,> >size>=>(>10>,>10>))> > # setting the parameter values> cmap>=> 'tab20'> > # plotting the heatmap> hm>=> sn.heatmap(data>=>data,> >cmap>=>cmap)> > # displaying the plotted heatmap> plt.show()> |
>
>
Ieșire:

Centrarea hărții de culori
Centrarea cmap-ului la 0 prin trecerea centru parametrul ca 0.
Python3
# importing the modules> import> numpy as np> import> seaborn as sn> import> matplotlib.pyplot as plt> > # generating 2-D 10x10 matrix of random numbers> # from 1 to 100> data>=> np.random.randint(low>=>1>,> >high>=>100>,> >size>=>(>10>,>10>))> > # setting the parameter values> cmap>=> 'tab20'> center>=> 0> > # plotting the heatmap> hm>=> sn.heatmap(data>=>data,> >cmap>=>cmap,> >center>=>center)> > # displaying the plotted heatmap> plt.show()> |
>
>
Ieșire:

Afișarea valorilor celulelor
Dacă vrem să afișăm valoarea celulelor, atunci trecem parametrul ei spun ca Adevărat. fmt este utilizat pentru a selecta tipul de date al conținutului celulelor afișate.
comutator java int
Python3
# importing the modules> import> numpy as np> import> seaborn as sn> import> matplotlib.pyplot as plt> > # generating 2-D 10x10 matrix of random numbers> # from 1 to 100> data>=> np.random.randint(low>=>1>,> >high>=>100>,> >size>=>(>10>,>10>))> > # setting the parameter values> annot>=> True> > # plotting the heatmap> hm>=> sn.heatmap(data>=>data,> >annot>=>annot)> > # displaying the plotted heatmap> plt.show()> |
>
>
Ieșire:

Personalizarea liniei de separare
Putem schimba grosimea și culoarea liniilor care separă celulele folosind lățimi de linii și linecolor parametrii respectiv.
Python3
# importing the modules> import> numpy as np> import> seaborn as sn> import> matplotlib.pyplot as plt> > # generating 2-D 10x10 matrix of random numbers> # from 1 to 100> data>=> np.random.randint(low>=>1>,> >high>=>100>,> >size>=>(>10>,>10>))> > # setting the parameter values> linewidths>=> 2> linecolor>=> 'yellow'> > # plotting the heatmap> hm>=> sn.heatmap(data>=>data,> >linewidths>=>linewidths,> >linecolor>=>linecolor)> > # displaying the plotted heatmap> plt.show()> |
>
>
Ieșire:

Ascunderea barei de culori
Putem dezactiva bara de culori setând cbar parametrul la Fals.
Python3
# importing the modules> import> numpy as np> import> seaborn as sn> import> matplotlib.pyplot as plt> > # generating 2-D 10x10 matrix of random numbers> # from 1 to 100> data>=> np.random.randint(low>=>1>,> >high>=>100>,> >size>=>(>10>,>10>))> > # setting the parameter values> cbar>=> False> > # plotting the heatmap> hm>=> sn.heatmap(data>=>data,> >cbar>=>cbar)> > # displaying the plotted heatmap> plt.show()> |
>
>
Ieșire:

Îndepărtarea etichetelor
Putem dezactiva eticheta x și eticheta y trecând False în xticklabels și yticlabels parametrii respectiv.
Python3
# importing the modules> import> numpy as np> import> seaborn as sn> import> matplotlib.pyplot as plt> > # generating 2-D 10x10 matrix of random numbers> # from 1 to 100> data>=> np.random.randint(low>=>1>,> >high>=>100>,> >size>=>(>10>,>10>))> > # setting the parameter values> xticklabels>=> False> yticklabels>=> False> > # plotting the heatmap> hm>=> sn.heatmap(data>=>data,> >xticklabels>=>xticklabels,> >yticklabels>=>yticklabels)> > # displaying the plotted heatmap> plt.show()> |
>
>
Ieșire:
