Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Matplotlib Problem
#1
Hi - I'm so desperate to get a script working, is anybody up for a challenge please?. It fails with this comment:

Error:
/usr/lib/python2.7/dist-packages/matplotlib/contour.py:1180: UserWarning: No contour levels were found within the data range. warnings.warn("No contour levels were found" <matplotlib.contour.QuadContourSet object at 0x7f67d4b47490> Traceback (most recent call last): File "init_collapse.py", line 114, in <module> csp=cs.collections[0].get_paths()[2] # path IndexError: list index out of range
[bThis is a snap from the external file of coordinates and heights:[/b]
Output:
3560081.703 -3384637.321 -116.19 3560091.703 -3384637.321 -114.481 3560101.703 -3384637.321 -112.772 3560111.703 -3384637.321 -111.063 3560121.703 -3384637.321 -109.354
This is how it is imported as the variable data:
Output:
[[ 3.56008170e+06 -3.38463732e+06 -1.16190000e+02] [ 3.56009170e+06 -3.38463732e+06 -1.14481000e+02] [ 3.56010170e+06 -3.38463732e+06 -1.12772000e+02]
This is a list of the variables Kxx, kyy, kelevation and collapse_depth that feeds into the failure variable cs
Output:
[[ 3564081.703 3564091.703 3564101.703 ..., 3565551.703 3565561.703 3565571.703] [ 3564081.703 3564091.703 3564101.703 ..., 3565551.703 3565561.703 3565571.703] [ 3564081.703 3564091.703 3564101.703 ..., 3565551.703 3565561.703 3565571.703] ..., [ 3564081.703 3564091.703 3564101.703 ..., 3565551.703 3565561.703 3565571.703] [ 3564081.703 3564091.703 3564101.703 ..., 3565551.703 3565561.703 3565571.703] [ 3564081.703 3564091.703 3564101.703 ..., 3565551.703 3565561.703 3565571.703]] [[-3389837.321 -3389837.321 -3389837.321 ..., -3389837.321 -3389837.321 -3389837.321] [-3389847.321 -3389847.321 -3389847.321 ..., -3389847.321 -3389847.321 -3389847.321] [-3389857.321 -3389857.321 -3389857.321 ..., -3389857.321 -3389857.321 -3389857.321] ..., [-3391607.321 -3391607.321 -3391607.321 ..., -3391607.321 -3391607.321 -3391607.321] [-3391617.321 -3391617.321 -3391617.321 ..., -3391617.321 -3391617.321 -3391617.321] [-3391627.321 -3391627.321 -3391627.321 ..., -3391627.321 -3391627.321 -3391627.321]] [[ 964.877 967.491 970.106 ..., 723.177 721.048 718.919] [ 966.833 969.941 973.05 ..., 722.591 720.469 718.348] [ 968.558 971.845 975.133 ..., 721.975 719.87 717.765] ..., [ 537.758 537.723 537.688 ..., 441.422 440.741 440.06 ] [ 535.511 535.425 535.339 ..., 438.624 438. 437.376] [ 533.265 533.128 532.991 ..., 435.826 435.26 434.693]] -204
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()
Larz60+ write Mar-14-2022, 09:55 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use BBCode in future posts.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Matplotlib: How do I convert Dates from Excel to use in Matplotlib JaneTan 1 3,161 Mar-11-2021, 10:52 AM
Last Post: buran
  Problem with matplotlib ncm1234 1 1,463 Sep-01-2020, 02:16 AM
Last Post: bowlofred
  Matplotlib problem ift38375 0 1,851 Jul-02-2019, 02:55 PM
Last Post: ift38375
  Matplotlib animation problem Potatoez 1 2,315 May-21-2019, 03:58 PM
Last Post: Potatoez
  Problem installing numpy and matplotlib achondrite 1 3,082 Jan-16-2019, 11:43 PM
Last Post: snippsat
  problem in plotting intraday results using matplotlib mr_byte31 0 2,925 Aug-20-2018, 11:32 AM
Last Post: mr_byte31

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020