from pylab import * from mpl_toolkits.mplot3d import Axes3D from matplotlib.cbook import get_sample_data from matplotlib._png import read_png import numpy as np import matplotlib.pyplot as plt import csv from mpl_toolkits.basemap import Basemap dir = "catalogs" range = [2019, 2019] i = range[0] def import_data(filepath): try: with open(filepath, 'rt') as csvfile: data = csv.reader(csvfile, delimiter=';') """ try: print("event") for row in data: event = row[0] except Exception as e: data = csv.reader(csvfile, delimiter=';') """ d0, d1, d2, d3, d4, d5, d6, d7, d8, d9, d10 = 0,0,0,0,0,0,0,0,0,0,0 for row in data: print(row) event = row[0] date = row[1] time = row[2] try: dlati = float(row[3]) except Exception as e: dlati = 0.0 try: dlong = float(row[4]) except Exception as e: dlong = 0.0 try: dprof = float(row[5])*-1 except Exception as e: dprof = 0.0 # check if anything is 0 and set color to blue, else to color red if dprof == 0.0 or dlong == 0.0 or dlati == 0.0: if dprof == 0.0: dprof = 1.0 color = "black" else: color = "white" d0 += 1 elif dprof >= -1.0 and dprof < 0.0: color = "red" d1 += 1 elif dprof >= -2.0 and dprof < -1.0: color = "fuchsia" d2 += 1 elif dprof >= -5.0 and dprof < -2.0: color = "orange" d3 += 1 elif dprof >= -7.5 and dprof < -5.0: color = "olive" d4 += 1 elif dprof >= -10.0 and dprof < -7.5: color = "gold" d5 += 1 elif dprof >= -20.0 and dprof < -10.0: color = "darkviolet" d6 += 1 elif dprof >= -40.0 and dprof < -20.0: color = "aqua" d7 += 1 elif dprof >= -60.0 and dprof < -40.0: color = "navy" d8 += 1 elif dprof >= -80.0 and dprof < -60.0: color = "cyan" d9 += 1 else: color = "green" d10 += 1 inten = row[6] # Inten. mag = row[7] # Mag. magt = row[8] # Tipo Mag. location = row[9] # Local x.append(dlong) y.append(dlati) z.append(dprof) c_list.append(color) print ("x:%s, y:%s, z:%s, loc:%s"%(dlong,dlati,dprof,location)) """ #if location.endswith("CANARIAS"): #if location.endswith("ITF"): #if location.endswith("IGC") or location.endswith("GRAN CANARIA"): #if location.endswith("ILP"): #if location.endswith("IHI"): #if location.endswith("IFV"): if location.endswith("ILZ"): x.append(dlong) y.append(dlati) z.append(dprof) c_list.append(color) print ("x:%s, y:%s, z:%s, loc:%s"%(dlong,dlati,dprof,location)) """ except Exception as e: print("def import_data failed: filepath = %s, e = '%s'" (filepath,e)) while i <= range[1]: filepath = "%s/%s.exp" % (dir,i) fig = plt.figure(i,figsize=(12,12)) x = [] y = [] z = [] c_list = [] import_data(filepath) ax = plt.axes(projection='3d') ax.scatter(x, y, z, c=c_list, label='Earthquakes Canary Islands: %s'%filepath) # Make legend, set axes limits and labels plt.title('%d'%i) ax.legend() ax.set_xticks(np.arange(-19,-11,1)) ax.set_yticks(np.arange(25,32,1)) ax.set_xlim(-19, -11) ax.set_ylim(25, 32) ax.set_zlim(-100.0, 1.0) ax.set_xlabel('X (Lon.)') ax.set_ylabel('Y (Lat.)') ax.set_zlabel('Z (Depth KM)') # Customize the view angle so it's easier to see that the scatter points lie # on the plane y=0 ax.view_init(elev=30, azim=-75) # azim -90 to 0 #n += 1 #plt.savefig("/home/fed/earthquakes/test.svg") out_png = "%s.png"%filepath plt.savefig(out_png) i += 1 plt.show()