Session Ready
Exercise

Contour & filled contour plots

Although plt.imshow() or plt.pcolor() are often used to visualize a 2-D array in entirety, there are other ways of visualizing such data without displaying all of the available sample values. One option is to use the array to compute contours that are visualized instead.

Two types of contour plot supported by Matplotlib are plt.contour() and plt.contourf() where the former displays the contours as lines and the latter displayed filled areas between contours. Both these plotting commands accept a two dimensional array from which the appropriate contours are computed.

In this exercise, you will visualize a 2-D array repeatedly using both plt.contour() and plt.contourf(). You will use plt.subplot() to display several contour plots in a common figure, using the meshgrid X, Y as the axes. For example, plt.contour(X, Y, Z) generates a default contour map of the array Z.

Don't forget to include the meshgrid in each plot for this exercise!

Instructions
100 XP
  • Using the meshgrid X, Y as axes for each plot:
    • Generate a default contour plot of the array Z in the upper left subplot.
    • Generate a contour plot of the array Z in the upper right subplot with 20 contours.
    • Generate a default filled contour plot of the array Z in the lower left subplot.
    • Generate a default filled contour plot of the array Z in the lower right subplot with 20 contours.
  • Improve the spacing between the subplots with plt.tight_layout() and display the figure.