히트맵 행렬의 값을 시각화하기 위해 색상을 사용하여 데이터를 그래픽으로 표현하는 것으로 정의됩니다. 여기서 보다 일반적인 값이나 활동성이 높은 값을 표현하려면 밝은 색상을 기본적으로 사용하며, 덜 일반적이거나 활동성 값을 나타낼 경우에는 어두운 색상을 선호합니다. 히트맵은 음영 행렬의 이름으로도 정의됩니다. Seaborn의 히트맵은 seaborn.heatmap() 함수를 사용하여 그릴 수 있습니다.
씨본.히트맵()
통사론: 씨본.히트맵( 데이터 , * , vmin=없음 , vmax=없음 , cmap=없음 , 중심=없음 , annot_kws=아니요 , 선폭=0 , linecolor='흰색' , cbar=참 , **크와르그 )
중요한 매개변수:
데이터: ndarray로 강제 변환할 수 있는 2D 데이터 세트입니다. vmin , v최대: 컬러맵을 고정하는 값. 그렇지 않으면 데이터 및 기타 키워드 인수에서 추론됩니다. cmap: 데이터 값에서 색상 공간으로의 매핑입니다. center: 서로 다른 데이터를 그릴 때 컬러맵을 중앙에 배치할 값입니다. annot: True인 경우 각 셀에 데이터 값을 씁니다. fmt: 주석을 추가할 때 사용할 문자열 형식 지정 코드입니다. linewidths: 각 셀을 나눌 선의 너비입니다. linecolor: 각 셀을 나눌 선의 색상입니다. cbar: 컬러바를 그릴지 여부입니다.
데이터를 제외한 모든 매개변수는 선택사항입니다.
보고: matplotlib.axes._subplots.AxesSubplot 유형의 객체
예시를 통해 히트맵을 이해해 보겠습니다.
기본 히트맵
기본 매개변수를 사용하여 히트맵 만들기 우리는 다음을 사용하여 10×10 2-D 데이터를 생성할 것입니다. 날짜() NumPy 모듈의 기능.
파이썬3
# 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()> |
>
>
산출:
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]]>

우리는 모든 예에서 이와 동일한 데이터를 사용할 것입니다.
컬러맵 고정
우리가 설정하면 분 값을 30으로 설정하고 vmax 값을 70으로 설정하면 30에서 70 사이의 값을 가진 셀만 표시됩니다. 이를 컬러맵 고정이라고 합니다.
파이썬3
# 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()> |
>
>
산출:

컬러맵 선택
이에 대해 우리는 cmap 매개변수. Matplotlib은 여러 색상 맵을 제공하므로 모두 볼 수 있습니다. 여기 . 이 예에서는 탭20 .
파이썬3
# 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()> |
>
>
산출:

컬러맵 중심 맞추기
다음을 전달하여 cmap을 0으로 중심화합니다. 센터 매개변수를 0으로 합니다.
파이썬3
# 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()> |
>
>
산출:

셀 값 표시
셀의 값을 표시하려면 매개변수를 전달합니다. 그들은 말한다 사실로. fmt 표시된 셀 내용의 데이터 유형을 선택하는 데 사용됩니다.
반응 테이블
파이썬3
# 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()> |
>
>
산출:

구분선 사용자 정의
다음을 사용하여 셀을 구분하는 선의 두께와 색상을 변경할 수 있습니다. 선폭 그리고 선색상 각각 매개변수.
파이썬3
# 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()> |
>
>
산출:

컬러바 숨기기
다음을 설정하여 컬러바를 비활성화할 수 있습니다. cbar 매개변수를 False로 설정합니다.
파이썬3
# 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()> |
>
>
산출:

라벨 제거
False를 전달하여 x 레이블과 y 레이블을 비활성화할 수 있습니다. xticklabels 그리고 yticklabels 각각 매개변수.
파이썬3
# 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()> |
>
>
산출:
