3

데이터 시각화에 관한 UDemy에 대한 강좌를 듣고 있습니다. (나는 당신에게 권하고 싶지만 스팸으로 보일지도 모릅니다), 그 과정을 시작하기 전에, 저는 matplotlib을 사용하여 시각화 작업을 수행했습니다. 그래서 Seaborn은 나에게 새로운.Python, Seaborn : corrplot을 복제하는 방법은 무엇입니까?

enter image description here

하지만 지금은 corrplot()가 사용되지 않습니다 :이 과정에서 그들은 다음과 같은 차트 같은 것을 생성 할 수 있습니다 corrplot() 기능에 대해 이야기. 나는 훨씬 더 원래의 corrplot() 출력을 좋아 물론

enter image description here

: 나는 시본 문서에서 찾고, 웹에 대한 몇 가지 링크 및 "가까이"나는 짓을했는지 봤는데 이것이다 그리고 구현하기가 더 쉬우 며, heatmap() 또는 다른 기능을 사용하여 동일한 작업을 수행하는 방법은 무엇입니까?

BTW : 차트를 만든 데이터가 다르면 첫 번째는 비디오 캡처에서 나오고 다른 하나는 내 PC의 스크린 샷이므로 값이 같지 않습니다.

답변

3

우선, corrplot()이 가치 하락된다는 사실은 사용자가 사용할 수 없다는 것을 의미하지 않습니다. seaborn의 이후 버전에서 제거되거나 다른 문제가 수반 될 수 있습니다. 그러나, 당신이 지금 당신에게주는 것에 만족한다면, 당신은 여전히 ​​그것을 사용할 수 있습니다.

corrplot과 비슷한 결과를 얻으려면 heatmap을 사용하려면 약간 줄거리를 조정해야 할 수도 있습니다.

예는 다음과 같다 :

import numpy as np; np.random.seed(1) 
import pandas as pd 
import seaborn.apionly as sns 
import matplotlib.pyplot as plt 

# Generate a random dataset 
cols = [s*4 for s in list("ABCD")] 
df = pd.DataFrame(data=np.random.rayleigh(scale=5, size=(100, 4)), columns=cols) 

# Compute the correlation matrix 
corr = df.corr() 
print(corr) 
# Generate a mask for the upper triangle 
mask = np.zeros_like(corr, dtype=np.bool) 
mask[np.triu_indices_from(mask)] = True 

# Set up the matplotlib figure 
fig, ax = plt.subplots() 

# Draw the heatmap with the mask and correct aspect ratio 
vmax = np.abs(corr.values[~mask]).max() 
sns.heatmap(corr, mask=mask, cmap=plt.cm.PuOr, vmin=-vmax, vmax=vmax, 
      square=True, linecolor="lightgray", linewidths=1, ax=ax) 
for i in range(len(corr)): 
    ax.text(i+0.5,len(corr)-(i+0.5), corr.columns[i], 
      ha="center", va="center", rotation=45) 
    for j in range(i+1, len(corr)): 
     s = "{:.3f}".format(corr.values[i,j]) 
     ax.text(j+0.5,len(corr)-(i+0.5),s, 
      ha="center", va="center") 
ax.axis("off") 
plt.show() 

enter image description here