#! /usr/bin/env python3 # def minmax_plot ( ): import matplotlib.pyplot as plt import numpy as np n = 101 x1 = -12 x2 = +12 x = np.linspace ( x1, x2, n ) y = np.sin ( x ) / x # # Patch the data. # y[x==0] = 1.0 plt.clf ( ) plt.plot ( x, y, 'g-', linewidth = 2 ) plt.grid ( True ) filename = 'sinc.png' plt.savefig ( filename ) print ( ' Graphics saved as "' + filename + '"' ) plt.show ( ) # # Now exhibit min, mean and max. # ymin = np.min ( y ) imin = np.argmin ( y ) xmin = x[imin] print ( ymin, imin, xmin ) ymean = np.mean ( y ) ymax = np.max ( y ) imax = np.argmax ( y ) xmax = x[imax] print ( ymax, imax, xmax ) plt.clf ( ) plt.plot ( x, y, 'g-', linewidth = 2 ) plt.plot ( [x1,x2], [ymax,ymax], 'b-' ) plt.plot ( [xmax,xmax], [0.0,ymax], 'b-' ) plt.plot ( [x1,x2], [ymin,ymin], 'r-' ) plt.plot ( [xmin,xmin], [0.0,ymin], 'r-' ) plt.plot ( [x1,x2], [ymean,ymean], 'c:', linewidth = 3 ) plt.plot ( [x1,x2], [0.0,0.0], 'k-' ) plt.grid ( True ) filename = 'sinc_marked.png' plt.savefig ( filename ) print ( ' Graphics saved as "' + filename + '"' ) plt.show ( ) # # Now exhibit points with y<0 # plt.clf ( ) plt.plot ( x, y, 'g-', linewidth = 2 ) plt.plot ( x[y<0], y[y<0], 'r.', markersize = 10 ) plt.plot ( [x1,x2], [0.0,0.0], 'k-' ) plt.grid ( True ) filename = 'sinc_negative.png' plt.savefig ( filename ) print ( ' Graphics saved as "' + filename + '"' ) plt.show ( ) return if ( __name__ == '__main__' ): minmax_plot ( )