I am trying to create a correlation matrix. creating a matrix works fine until I try to add a color panel.
This is my current code:
def corr_matrix(data): '''function to find the mean for days''' data=data.ix[:,1:].corr(method='pearson') row_lab=[] col_lab=[] for i in data: row_lab.append(i) col_lab.append(i) column_labels = col_lab row_labels = row_lab data=np.round(data.corr(method='pearson').abs(), decimals=2) data=np.array(data) fig, ax = plt.subplots() plt.axis('tight') heatmap = ax.pcolor(data, cmap='RdPu'), plt.colorbar(mappable=heatmap)
I tried plt.colorbar() . This does not work either. Any help would be great!
I examined this question: AttributeError when adding colorbar to matplotlib , but the answers do not seem to work :(
That's my fault:
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Users\AClayton\WinPython-64bit-2.7.5.3\python-2.7.5.amd64\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 538, in runfile execfile(filename, namespace) File "C:/Users/AClayton/Desktop/HData/correlation.py", line 152, in <module> cmat=corr_matrix(all_data) File "C:/Users/AClayton/Desktop/HData/correlation.py", line 88, in corr_matrix plt.colorbar(mappable=heatmap)
EDIIT all_data replaced with data as it was a typo.
data=pd.DataFrame(np.random.rand(10,10)) causes an error
python matplotlib colorbar
Ashleigh clayton
source share