x, y = cst.data.mapdata('coastlines', 'high', extent, 10.0) x, y = proj(x, y) ax.plot(x - 360.0, y, 'k-', lw=0.5) # source mts = 'scsn-mts-14383980.py' mts = cst.util.load(mts) x = mts.longitude y = mts.latitude x, y = proj(x, y) if 0: ax.plot(x, y, 'k*', ms=12, mew=1.0, mec='k', mfc='none') else: m = mts.double_couple_clvd m = m['mzz'], m['mxx'], m['myy'], m['mxz'], -m['myz'], -m['mxy'] b = beachball.Beach(m, xy=(x, y), width=8000, linewidth=0.5, facecolor='k') ax.add_collection(b) # stations sta = np.loadtxt('station-list.txt', 'S8, f, f, f') x, y = proj(sta['f2'], sta['f1']) ax.plot(x, y, 'k^', markersize=5) for s, y, x, z in sta: x, y = proj(x, y) ax.text(x, y - 1800, s.split('.')[-1], ha='center', va='top') # finish up axis = bounds[0] + bounds[1] #ax.set_aspect( aspect ) ax.set_xticks([]) ax.set_yticks([])
def maps(station_list, origin, strike, dip, rake, plot_file): """ Plotting a map with epicenter and possible stations according to distance and a map with with the beachball """ # sets figure's dimensions _fig_x = 10 _fig_y = 10 fig = plt.figure(figsize=(_fig_x, _fig_y)) # calculating map space _max = max(_station.distance_by_origin for _station in station_list) _max = int(round(_max * 1000 * 2)) _size = _max + int(round(_max / 7.0)) _diff = kilometer2degrees(round(_size / (2 * 2.0 * 1000))) parallels = [ round(origin.latitude, 2), round((origin.latitude - _diff), 2), round((origin.latitude + _diff), 2) ] meridians = [ round(origin.longitude, 2), round((origin.longitude - _diff), 2), round((origin.longitude + _diff), 2) ] m = Basemap(projection='laea', lat_0=origin.latitude, lon_0=origin.longitude, lat_ts=origin.latitude, resolution='i', area_thresh=0.1, width=_size, height=_size) m.drawparallels(parallels, labels=[1, 0, 0, 0], color='grey', fontsize=10) m.drawmeridians(meridians, labels=[0, 0, 0, 1], color='grey', fontsize=10) m.drawrivers(color='aqua') m.drawcoastlines(color='0.2') m.drawcountries(color='0.4') m.drawmapboundary(fill_color='aqua') m.fillcontinents(color='coral', lake_color='aqua') x, y = m(origin.longitude, origin.latitude) # epicenter m.scatter(x, y, 1, color="#FFFF00", marker="*", zorder=3, linewidths=2, edgecolor="k") # beachball ax = plt.gca() b = beach.Beach([strike, dip, rake], xy=(x, y), width=35000, linewidth=1, facecolor='r') b.set_zorder(10) ax.add_collection(b) # stations for station in station_list: x, y = m(station.longitude, station.latitude) m.scatter(x, y, 150, color="#33CC00", marker="^", zorder=3, linewidths=1, edgecolor="k") plt.text(x + 1800, y + 3000, station.code, family="monospace", fontsize=12) fig.savefig(plot_file)
def correlation(depth_x, correlation_y, dc, beachballs, plot_file): """ Illustrates an example for plotting beachballs and data points on line with specific color based on values with a labelled colorbar. """ # sets figure's dimensions _fig_x = 30 _fig_y = 20 # creates figure fig, ax = plt.subplots(figsize=(_fig_x, _fig_y)) # plots (depth_x, correlation_y) points on line ax.plot(depth_x, correlation_y, '--', linewidth=2, color='k') # creates a grid on the (main) plot ax.grid() # sets labels plt.xlabel('Depth (km)') plt.ylabel('Correlation') # sets font size plt.rcParams.update({'font.size': 28}) # sets fixed y-axis range plt.ylim((0, 1)) # sets margins on the plot plt.margins(0.1) # sets color canvas for coloring beachball cm = plt.cm.jet # creates a colorbar at the right of main plot: divider = make_axes_locatable(ax) # makes room for colorbar cax = divider.append_axes("right", size="2%", pad=1) # set values to colorbar norm = colors.Normalize(vmin=0, vmax=100) # creates colorbar on specific axes, norm, canvas color and orientation cb1 = colorbar.ColorbarBase(cax, norm=norm, cmap=cm, orientation='vertical') # sets colorbar label cb1.set_label('DC%') # plotting beachballs on specific x-axis and y-axis # with a color based on the data_dc values (normalized to 0-1) for i in xrange(len(depth_x)): # sets color value color = cm(dc[i] / 100.0) # draws beachball b = beach.Beach([beachballs[i][0], beachballs[i][1], beachballs[i][2]], xy=(depth_x[i], correlation_y[i]), width=80, linewidth=1, facecolor=color) # holds the aspect but fixes positioning: b.set_transform(transforms.IdentityTransform()) # brings the all patches to the origin (0, 0). for p in b._paths: p.vertices -= [depth_x[i], correlation_y[i]] # uses the offset property of the collection to position the patches b.set_offsets((depth_x[i], correlation_y[i])) b._transOffset = ax.transData # adds beachball to plot ax.add_collection(b) # saves plot to file plt.savefig(plot_file, dpi=fig.dpi)
def contour(time_list, depth_list, dc_list, corr_list, beachball_list, plot_file): """ Plotting contour """ # sets figure's dimensions _fig_x = 60 _fig_y = 40 # creates figure fig, ax = plt.subplots(figsize=(_fig_x, _fig_y)) # creates a grid on the (main) plot ax.grid() # sets labels plt.xlabel('Time (sec)') plt.ylabel('Centroid Depth (km)') # sets font size plt.rcParams.update({'font.size': 28}) # sets margins on the plot plt.margins(0.05) tri.Triangulation(time_list, depth_list) levels = [0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.8, 1.0] cont = plt.tricontour(time_list, depth_list, corr_list, len(levels), levels=levels, linewidths=0.5, colors='k') plt.tricontourf(time_list, depth_list, corr_list, len(levels), levels=levels, cmap=plt.cm.cool) plt.clabel(cont) cm = plt.cm.copper_r #gia dc # plotting beachballs on specific x-axis and y-axis # with a color based on the data_dc values (normalized to 0-1) _max_corr = max(corr_list) _index = corr_list.index(_max_corr) for i in xrange(len(beachball_list)): if i == _index: # sets best beachball's color value to red _color = 'red' _width = 45 # bigger beachball for best match else: # sets beachball's color value _color = cm(dc_list[i] / 100.0) _width = 35 # draws beachball b = beach.Beach( [beachball_list[i][0], beachball_list[i][1], beachball_list[i][2]], xy=(time_list[i], depth_list[i]), width=_width, linewidth=1, facecolor=_color) # holds the aspect but fixes positioning: b.set_transform(transforms.IdentityTransform()) # brings the all patches to the origin (0, 0). for p in b._paths: p.vertices -= [time_list[i], depth_list[i]] # uses the offset property of the collection to position the patches b.set_offsets((time_list[i], depth_list[i])) b._transOffset = ax.transData # adds beachball to plot ax.add_collection(b) # creates a colorbar at the right of main plot divider = make_axes_locatable(ax) # makes room for colorbar cax = divider.append_axes("right", size="1%", pad=0.5) # set values to colorbar norm = colors.Normalize(vmin=0.0, vmax=1.0) # creates colorbar on specific axes, norm, canvas color and orientation colorbar.ColorbarBase(cax, cmap=plt.cm.cool, norm=norm, orientation='vertical', label='Correlation') cax = divider.append_axes("right", size="1%", pad=1.5) # set values to colorbar norm = colors.Normalize(vmin=0, vmax=100) # creates colorbar on specific axes, norm, canvas color and orientation colorbar.ColorbarBase(cax, cmap=plt.cm.copper_r, norm=norm, orientation='vertical', label='DC%') # save plot to file plt.savefig(plot_file, dpi=fig.dpi)
cax = divider.append_axes("right", size="2%", pad=1) # set values to colorbar norm = colors.Normalize(vmin=0, vmax=100) # creates colorbar on specific axes, norm, canvas color and orientation cb1 = colorbar.ColorbarBase(cax, norm=norm, cmap=cm, orientation='vertical') # sets colorbar label cb1.set_label('DC%') # plotting beachballs on specific x-axis and y-axis with a color based on the data_dc values (normalized to 0-1) for i in xrange(len(data_x)): # sets color value color = cm(data_dc[i] / 100.0) # draws beachball b = beach.Beach( [data_beachballs[i][0], data_beachballs[i][1], data_beachballs[i][2]], xy=(data_x[i], data_y[i]), width=150, linewidth=1, facecolor=color) # holds the aspect but fixes positioning: b.set_transform(transforms.IdentityTransform()) # brings the all patches to the origin (0, 0). for p in b._paths: p.vertices -= [data_x[i], data_y[i]] # uses the offset property of the collection to position the patches b.set_offsets((data_x[i], data_y[i])) b._transOffset = ax.transData # adds beachball to plot ax.add_collection(b)