Matplotlib Problem - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Matplotlib Problem (/thread-36650.html) |
Matplotlib Problem - DaveG - Mar-14-2022 Hi - I'm so desperate to get a script working, is anybody up for a challenge please?. It fails with this comment: [bThis is a snap from the external file of coordinates and heights:[/b] This is how it is imported as the variable data: This is a list of the variables Kxx, kyy, kelevation and collapse_depth that feeds into the failure variable cs This is the script up to the scrash point.""" A script that generates initial bathymetry and size of displacement of the seafloor (representing caldera collapse in our case) initial bathymetry: crater filled final bathymetry: present day bathymetry INPUT PARAMETERS -- OUTPUT FILES -- mesh before collapse (default name: -- displacement of sea floor (default name: collapse.xyt) """ from scipy import * from pylab import * from numpy import * import sys from degrees2utm import * from copy import deepcopy #from matplotlib.patches import PathPatch from matplotlib.pyplot import * #close('all') # ================================================================================= # INPUT SECTION BEGIN # ================================================================================= meshfile='GRID7_Before.xyz' # !!!!!!!!!!!!!!!!!!!!sr collapse_duration=60.0 # in seconds collapse_depth=-204 # depth of the filling cup meshfile_start='GRID7_Before.xyz' # file with output file_ls="collapse.xyt" # file with displacement ############# GENERAL SWITCHES; for plotting purposes plot_bathymetry_allmesh=False # original mesh plot_bathymetry_kolumbo=False # only small region around Kolumbo is extracted plot_collapsed_volume=False # show collapse volume plot_before_after=False # plot mesh before and after the collapse plot_debugfig=False # debug figures; for checking # ================================================================================= # INPUT SECTION END # ================================================================================= print 'reading mesh file data; might take some time' data=genfromtxt(meshfile) nx=1521 # dimensions of the mesh file ny=947 elevation=data[:,2] xx=data[:,0] yy=data[:,1] #print (xx) #print (yy) elevation=elevation.reshape((ny,nx)) # bathymetry/topography xx=xx.reshape((ny,nx)) yy=yy.reshape((ny,nx)) if (plot_bathymetry_allmesh or plot_bathymetry_kolumbo or plot_collapsed_volume or plot_before_after): #mlab.close(all) from mayavi import mlab if plot_bathymetry_allmesh: mlab.figure(size=(1000,800)) scale=0.00005 cmax=500 s=mlab.surf(xx.T,yy.T,-elevation.T,vmax=cmax,vmin=-cmax,colormap='GnBu',warp_scale=scale) mlab.title('Bath/topo - original computation grid') lut = s.module_manager.scalar_lut_manager.lut.table.to_array() ilut = lut[::-1] # and finally we put this LUT back in the surface object. We could have s.module_manager.scalar_lut_manager.lut.table = ilut # We need to force update of the figure now that we have changed the LUT. mlab.draw() #mlab.view(40, 85) mlab.view() cmax=500 # color scale lmin=400 # cutting from east lmax=550 # cutting from west rmin=520 # north of santorini rmax=700 # south of santorini ###### kolumbo data kxx=xx[rmin:rmax,lmin:lmax] kyy=yy[rmin:rmax,lmin:lmax] kelevation=elevation[rmin:rmax,lmin:lmax] print (kxx) print (kyy) print (kelevation) if plot_bathymetry_kolumbo: mlab.figure(size=(1000,800)) scale=0.00005 ###### mayavi plotting s=mlab.surf(kxx.T,kyy.T,-kelevation.T,vmax=cmax,vmin=-cmax,colormap='GnBu',warp_scale=scale) lut = s.module_manager.scalar_lut_manager.lut.table.to_array() ilut = lut[::-1] s.module_manager.scalar_lut_manager.lut.table = ilut mlab.draw() mlab.view() ################################################## collapse bathymetry data print (collapse_depth) collapse_steps=2 # can be changed by USER collapse_starttime=0.0 # in second; can be changed by USER collapse_times=linspace(0,collapse_duration,collapse_steps) cs=contour(kxx,kyy,-kelevation,[collapse_depth]) csp=cs.collections[0].get_paths()[2] # path csv=csp.vertices # vertices csv_x=csv[:,0] csv_y=csv[:,1] if (not plot_debugfig): close() |