#! /usr/bin/env python3 # def temperature_contour ( ): import numpy as np import matplotlib.pyplot as plt # # Boost m = 5, n = 4 to m = 50, n = 40 for better picture. # m = 50 n = 40 left = 0.0 right = 3.0 bottom = 4.0 top = 8.0 x = np.linspace ( left, right, n ) y = np.linspace ( top, bottom, m ) X, Y = np.meshgrid ( x, y ) T = X**2 + 3.0 * np.sin ( Y ) # # Demonstrate indexing. # i = m // 2 j = n // 2 print ( '' ) print ( ' Array indices [', i, ',', j, '] correspond to' ) print ( ' X[i,j] = ', X[i,j], ' Y[i,j] = ', Y[i,j], ' T[i,j] = ', T[i,j] ) # # Plot the temperature field. # plt.clf ( ) plt.contour ( X, Y, T ) # plt.contourf ( X, Y, T ) plt.colorbar ( ) filename = 'temperature_contour.png' plt.savefig ( filename ) print ( ' Graphics saved as "' + filename + '"' ) plt.show ( ) plt.close ( ) return if ( __name__ == "__main__" ): temperature_contour ( )