#! /usr/bin/env python3 # def sombrero_surface ( ): #*****************************************************************************80 # ## sombrero_surface() draws a surface plot of sombrero data. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 19 April 2019 # # Author: # # John Burkardt # import matplotlib.pyplot as plt import numpy as np from mpl_toolkits.mplot3d import Axes3D from matplotlib import cm print ( '' ) print ( 'sombrero_surface():' ) print ( ' Make a surface plot Z(X,Y) of the sombrero function.' ) # # Set up X, Y grid and Z data. # xvec = np.linspace( -8.0, 8.0, 33 ) yvec = np.linspace( -8.0, 8.0, 33 ) xmat, ymat = np.meshgrid ( xvec, yvec ) rmat = np.sqrt ( xmat**2 + ymat**2 ) zmat = np.sin ( rmat ) / rmat zmat[ rmat == 0 ] = 1.0 # # Form the figure. # fig = plt.figure ( ) ax = fig.add_subplot ( 111, projection='3d' ) surface = ax.plot_surface ( xmat, ymat, zmat, \ cmap = cm.twilight, edgecolor = 'none' ) fig.colorbar ( surface ) ax.set_title ( 'The sombrero function', fontsize = 16 ) ax.set_xlabel ( '<--- X --->', fontsize = 16 ) ax.set_ylabel ( '<--- Y --->', fontsize = 16 ) ax.set_zlabel ( '<--- Z(X,Y) --->', fontsize = 16 ) filename = 'sombrero_surface.png' plt.savefig ( filename ) print ( ' Graphics saved as "%s"' % ( filename ) ) plt.show ( ) plt.close ( ) return if ( __name__ == '__main__' ): sombrero_surface ( )