Time for action – drawing a filled contour plot
We will draw a filled contour plot of the three-dimensional mathematical function in the previous Time for Action. The code is also pretty similar. One key difference is that we don’t need the 3d
projection parameter any more. To draw the filled contour plot we need this line of code:
ax.contourf(x, y, z)
This gives us the following filled contour plot.
What just happened?
We created a filled contour plot of a three-dimensional mathematical function (see contour.py
):
import matplotlib.pyplot as plt import numpy as np from matplotlib import cm fig = plt.figure() ax = fig.add_subplot(111) u = np.linspace(-1, 1, 100) x, y = np.meshgrid(u, u) z = x ** 2 + y ** 2 ax.contourf(x, y, z) plt.show()