matplotlib日常练习(3)

Heatmap

import pandas as pd
# Read the data from a csv file into pandas data frame
wine_quality = pd.read_csv('winequality.csv', delimiter=';')

# Get correlation matrix of all attributes of wine_quality
corr = wine_quality.corr()

plt.figure(figsize=(12,9))
plt.imshow(corr,cmap='hot');
plt.colorbar()
plt.xticks(range(len(corr)),corr.columns, rotation=20)
plt.yticks(range(len(corr)),corr.columns);

等高线图

import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
from matplotlib import cm

# Read Loss, theta0 and theta1 values
Loss = pd.read_excel('Loss.xlsx')
theta0_vals = pd.read_excel('theta0.xlsx')
theta1_vals = pd.read_excel('theta1.xlsx')

fig = plt.figure(figsize=(12,8))
X, Y = np.meshgrid(theta0_vals, theta1_vals)
CS = plt.contour(X, Y, Loss, np.logspace(-2,3,20), cmap=cm.coolwarm)
plt.clabel(CS, inline=1, fontsize=10)

# Plot the minimum point(Theta at Minimum cost)
theta = [-3.6, 1.1]
plt.plot(theta[0], theta[1], 'rx', markersize=15, linewidth=2)
plt.show()

你可能感兴趣的:(matplotlib日常练习(3))