- Matplotlib 3.0 Cookbook
- Srinivasa Rao Poladi
- 97字
- 2021-08-13 15:15:59
How to do it...
The following is the code block that plots a heatmap of the correlation matrix:
- Read the data from a CSV file into a pandas DataFrame:
wine_quality = pd.read_csv('winequality.csv', delimiter=';')
- Get the correlation matrix of all attributes of wine_quality:
corr = wine_quality.corr()
- Specify the figure size:
plt.figure(figsize=(12,9))
- Plot the heatmap:
plt.imshow(corr,cmap='hot')
- Plot the colorbar to map which color represents which data values:
plt.colorbar()
- Label the x and y axis ticks. Show the x axis labels with 20 degrees of rotation:
plt.xticks(range(len(corr)),corr.columns, rotation=20)
plt.yticks(range(len(corr)),corr.columns)
- Display the plot on the screen:
plt.show()