2017-04-19 14 views
3

私はデータ視覚化に関するUDemyのコースを取っています(私はそれをお勧めしますが、それは迷惑メールのように見えるかもしれません)。そのコースの前に、私は視覚化のためにmatplotlibを使用しています。私には新しい。Python、Seaborn:corrplotを複製する方法は?

enter image description here

しかし、今、corrplot()が廃止されました:もちろん、彼らは以下の表のようなものを作ることができcorrplot()機能、について話しています。 、私はずっと元corrplot()出力が好きで、もちろん

enter image description here

:私はSeabornのドキュメントで見ていると、ウェブ上でいくつかのリンク、および「近い」私がやったきたことはこれですその道をより簡単に実装するには、heatmap()やその他の機能を使って同じことをする方法は何でしょうか?

BTW:チャートを作成したデータは異なります。最初のものはビデオのキャプチャから得られ、もう1つは自分のPCのスクリーンショットであるため、値は同じではありません。

答えて

3

まず、corrplot()が償却されているということは、使用できないということを意味するものではありません。それはちょうどそれが海軍の将来のバージョンで削除されるか、それに伴ういくつかの他の問題がある可能性が高いです。しかし、あなたが今あなたに与えるものに満足しているなら、あなたはまだそれを使用するかもしれません。

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

関連する問題