Matplotlib 3.0 Cookbook
上QQ阅读APP看书,第一时间看更新

How to do it...

The following code block plots a correlation matrix with a Blues colormap:

  1. Read the winequality data from the Excel file:
wine_quality = pd.read_csv('winequality.csv', delimiter=';')
corr = wine_quality.corr()

  1. Define the figure and its size:
plt.figure(figsize=(12,8))
  1. Plot the correlation map, the associated x and y ticks, and the colorbar:
plt.imshow(corr, cmap='Blues')
plt.colorbar()
plt.xticks(range(len(corr)),corr.columns, rotation=45)
plt.yticks(range(len(corr)),corr.columns)
  1. Display the figure on the screen:
plt.show()