from matplotlib import cm import matplotlib.pyplot as plt import numpy as np import platform print ( '' ) print ( 'contours():' ) print ( ' Use meshgrd to sample a .' ) # # Create the mesh vectors. # xvec = np.linspace ( -2.0, 2.0, 31 ) yvec = np.linspace ( -2.0, 2.0, 31 ) # # Create the mesh matrices. # X, Y = np.meshgrid ( xvec, yvec ) # # Evaluate the function at the mesh points. # Z = 2 * X**2 - 1.05 * X**4 + X**6 / 6 + X * Y + Y**2 # # Plot # plt.clf ( ) plt.contourf ( X, Y, Z, cmap = cm.Pastel1 ) plt.contour ( X, Y, Z, levels = 35 ) plt.axis ( 'equal' ) plt.title ( 'A contour plot', fontsize = 16 ) plt.xlabel ( '<--- X --->', fontsize = 16 ) plt.ylabel ( '<--- Y --->', fontsize = 16 ) filename = 'contours.png' plt.savefig ( filename ) print ( ' Graphics saved as "%s"' % ( filename ) ) plt.show ( ) plt.close ( )