#! /usr/bin/env python3 # def volcano_fill_contour ( ): #*****************************************************************************80 # ## volcano_fill_contour draws a filled contour plot of volcano (X,Y,Z) data. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 03 May 2019 # # Author: # # John Burkardt # import matplotlib.pyplot as plt import numpy as np from matplotlib import cm print ( '' ) print ( 'volcano_fill_contour:' ) print ( ' Make a filled contour plot Z(X,Y) of volcano elevation data.' ) # # Read the Z data from the file. # zmat = np.loadtxt ( 'volcano_data.txt', dtype = 'f', delimiter = ' ' ) # # We have to create a grid of X and Y values corresponding to Z. # m, n = zmat.shape print ( ' Z data has %d rows and %d columns' % ( m, n ) ) xvec = np.linspace ( 0, n, n ) yvec = np.linspace ( 0, m, m ) xmat, ymat = np.meshgrid ( xvec, yvec ) # # Form the figure. # levels = 15 ax = plt.figure ( ) plt.contourf ( xmat, ymat, zmat, levels, cmap = cm.coolwarm ) plt.title ( 'Filled contour plot of Volcano', fontsize = 16 ) plt.xlabel ( '<--- X --->', fontsize = 16 ) plt.ylabel ( '<--- Y --->', fontsize = 16 ) filename = 'volcano_fill_contour.png' plt.savefig ( filename ) print ( '' ) print ( ' Graphics saved as "%s"' % ( filename ) ) plt.show ( block = False ) def volcano_line_contour ( ): #*****************************************************************************80 # ## volcano_line_contour draws a filled contour plot of volcano (X,Y,Z) data. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 03 May 2019 # # Author: # # John Burkardt # import matplotlib.pyplot as plt import numpy as np from matplotlib import cm print ( '' ) print ( 'volcano_line_contour:' ) print ( ' Make a line contour plot Z(X,Y) of volcano elevation data.' ) # # Read the Z data from the file. # zmat = np.loadtxt ( 'volcano_data.txt', dtype = 'f', delimiter = ' ' ) # # We have to create a grid of X and Y values corresponding to Z. # m, n = zmat.shape print ( ' Z data has %d rows and %d columns' % ( m, n ) ) xvec = np.linspace ( 0, n, n ) yvec = np.linspace ( 0, m, m ) xmat, ymat = np.meshgrid ( xvec, yvec ) # # Form the figure. # levels = 15 ax = plt.figure ( ) plt.contour ( xmat, ymat, zmat, levels, cmap = cm.coolwarm ) plt.title ( 'Line contour plot of Volcano', fontsize = 16 ) plt.xlabel ( '<--- X --->', fontsize = 16 ) plt.ylabel ( '<--- Y --->', fontsize = 16 ) filename = 'volcano_line_contour.png' plt.savefig ( filename ) print ( '' ) print ( ' Graphics saved as "%s"' % ( filename ) ) plt.show ( block = False ) def volcano_surface ( ): #*****************************************************************************80 # ## volcano_surface draws a surface plot of volcano (X,Y,Z) 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 ( 'volcano_surface:' ) print ( ' Make a surface plot Z(X,Y) of volcano elevation data.' ) # # Read the Z data from the file. # zmat = np.loadtxt ( 'volcano_data.txt', dtype = 'f', delimiter = ' ' ) # # We have to create a grid of X and Y values corresponding to Z. # m, n = zmat.shape print ( ' Z data has %d rows and %d columns' % ( m, n ) ) xvec = np.linspace ( 0, n, n ) yvec = np.linspace ( 0, m, m ) xmat, ymat = np.meshgrid ( xvec, yvec ) # # Form the figure. # fig = plt.figure ( ) ax = fig.add_subplot ( 111, projection = '3d' ) ax.plot_surface ( xmat, ymat, zmat, \ cmap = cm.coolwarm, edgecolor = 'none' ) ax.set_title ( 'Surface plot of Volcano', fontsize = 16 ) ax.set_xlabel ( '<--- X --->', fontsize = 16 ) ax.set_ylabel ( '<--- Y --->', fontsize = 16 ) ax.set_zlabel ( '<--- Z --->', fontsize = 16 ) filename = 'volcano_surface.png' plt.savefig ( filename ) print ( ' Graphics saved as "%s"' % ( filename ) ) plt.show ( block = False ) def code6(): #*****************************************************************************80 # ## code6() does line contour, color contour, and surface plots of volcano data. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 26 August 2021 # # Author: # # John Burkardt # import platform print ( '' ) print ( 'code6():' ) print ( ' Python version: %s' % ( platform.python_version ( ) ) ) print ( ' Create three plots of volcano data.' ) volcano_fill_contour ( ) volcano_line_contour ( ) volcano_surface ( ) print ( '' ) print ( 'code6():' ) print ( ' Normal end of execution.' ) if ( __name__ == '__main__' ): code6()