matplotlib contour display

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

# Calculate the height value corresponding to x, y coordinates
def f(x, y):
return (1-x/2+x**5+y**3) * np.exp(-x**2-y**2)

# Generate x,y data
n = 256
x = np.linspace(-3, 3, n)
y = np.linspace(-3, 3, n)

# Generate mesh grid-like data from x, y data, because the contour line is displayed by adding a height value
X, Y = np.meshgrid(x, y)

# Fill the contour line on the basis of the grid
plt.contourf(X, Y, f(X, Y), 20, cmap=plt.cm.hot)
# add contour
C = plt.contour(X, Y, f(X, Y), 20)
plt .clabel(C, inline=True, fontsize=12)
# show chart
plt.show()

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325028408&siteId=291194637