contour做的云图不是填充的,而contourf画的云图是填充的
来两个例子一目了然,代码可用。(本文例子来自matplotlib管网)
contour函数
contour([X, Y,] Z, [levels], **kwargs)
X, Y, The coordinates of the values in Z.
X and Y must both be 2-D with the same shape as Z (e.g. created via numpy.meshgrid), or they must both be 1-D such that len(X) == M is the number of columns in Z and len(Y) == N is the number of rows in Z.
If not given, they are assumed to be integer indices, i.e. X = range(M), Y = range(N).
Z array-like(N, M)
The height values over which the contour is drawn.
levels int or array-like, optional
Determines the number and positions of the contour lines / regions.
If an int n, use MaxNLocator, which tries to automatically choose no more than n+1 “nice” contour levels between vmin and vmax.
If array-like, draw contour lines at the specified levels. The values must be in increasing order.
import matplotlib
import numpy as np
import matplotlib.cm as cm
import matplotlib.pyplot as plt
delta = 0.025
x = np.arange(-3.0, 3.0, delta)
y = np.arange(-2.0, 2.0, delta)
X, Y = np.meshgrid(x, y)
Z1 = np.exp(-X**2 - Y**2)
Z2 = np.exp(-(X - 1)**2 - (Y - 1)**2)
Z = (Z1 - Z2) * 2
fig, ax = plt.subplots()
CS = ax.contour(X, Y, Z)
ax.clabel(CS, inline=True, fontsize=10)
ax.set_title('Simplest default with labels')<