#! /usr/bin/env python3 # def volcano_contour_fill ( ): #*****************************************************************************80 # ## volcano_contour_fill 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_contour_fill():' ) 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_contour_fill.png' plt.savefig ( filename ) print ( ' Graphics saved as "%s"' % ( filename ) ) plt.show ( block = False ) plt.close ( ) def volcano_contour_line ( ): #*****************************************************************************80 # ## volcano_contour_line() draws a contour line 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_contour_line():' ) print ( ' Make a contour line 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 - 1, n ) yvec = np.linspace ( 0, m - 1, m ) xmat, ymat = np.meshgrid ( xvec, yvec ) # # Form the figure. # levels = 15 plt.contour ( xmat, ymat, zmat, levels, cmap = cm.coolwarm ) plt.title ( 'Contour line plot of Volcano', fontsize = 16 ) plt.xlabel ( '<--- X --->', fontsize = 16 ) plt.ylabel ( '<--- Y --->', fontsize = 16 ) filename = 'volcano_contour_line.png' plt.savefig ( filename ) print ( ' Graphics saved as "%s"' % ( filename ) ) plt.show ( block = False ) plt.close ( ) 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 ) plt.close ( ) def code6(): #*****************************************************************************80 # ## code6() does contour line, contour color, 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_contour_fill ( ) volcano_contour_line ( ) volcano_surface ( ) print ( '' ) print ( 'code6():' ) print ( ' Normal end of execution.' ) if ( __name__ == '__main__' ): code6()