def DrapedOverHillshade(FileName, DrapeName, thiscmap='gray', drape_cmap='gray', colorbarlabel='Elevation in meters', clim_val=(0, 0), drape_alpha=0.6, ShowColorbar=False): import matplotlib.pyplot as plt import matplotlib.lines as mpllines from mpl_toolkits.axes_grid1 import AxesGrid label_size = 20 #title_size = 30 axis_size = 28 # Set up fonts for plots rcParams['font.family'] = 'sans-serif' rcParams['font.sans-serif'] = ['arial'] rcParams['font.size'] = label_size hillshade = Hillshade(FileName) #hillshade = LSDMap_IO.ReadRasterArrayBlocks(DrapeName) raster_drape = LSDMap_IO.ReadRasterArrayBlocks(DrapeName) # now get the extent extent_raster = LSDMap_IO.GetRasterExtent(FileName) x_min = extent_raster[0] x_max = extent_raster[1] y_min = extent_raster[2] y_max = extent_raster[3] # make a figure, sized for a ppt slide fig = plt.figure(1, facecolor='white', figsize=(10, 7.5)) if ShowColorbar: grid = AxesGrid( fig, 111, nrows_ncols=(1, 1), axes_pad=(0.45, 0.15), label_mode="1", share_all=True, cbar_location="right", cbar_mode="each", cbar_size="7%", cbar_pad="2%", ) else: grid = AxesGrid( fig, 111, nrows_ncols=(1, 1), axes_pad=(0.45, 0.15), label_mode="1", share_all=True, ) # now get the tick marks n_target_tics = 5 xlocs, ylocs, new_x_labels, new_y_labels = GetTicksForUTM( FileName, x_max, x_min, y_max, y_min, n_target_tics) print "xmax: " + str(x_max) print "xmin: " + str(x_min) print "ymax: " + str(y_max) print "ymin: " + str(y_min) im = grid[0].imshow(hillshade[::-1], thiscmap, extent=extent_raster, interpolation="nearest") #im = grid[0].imshow(raster, thiscmap, interpolation="nearest") if ShowColorbar: cbar = grid.cbar_axes[0].colorbar(im) cbar.set_label_text(colorbarlabel) # set the colour limits print "Setting colour limits to " + str(clim_val[0]) + " and " + str( clim_val[1]) if (clim_val == (0, 0)): print "I don't think I should be here" im.set_clim(0, np.max(hillshade)) else: print "Now setting colour limits to " + str( clim_val[0]) + " and " + str(clim_val[1]) im.set_clim(clim_val[0], clim_val[1]) # Now for the drape: it is in grayscape im = grid[0].imshow(raster_drape[::-1], drape_cmap, extent=extent_raster, alpha=drape_alpha, interpolation="nearest") # This affects all axes because we set share_all = True. grid.axes_llc.set_xlim(x_min, x_max) grid.axes_llc.set_ylim(y_max, y_min) grid.axes_llc.set_xticks(xlocs) grid.axes_llc.set_yticks(ylocs) grid.axes_llc.set_xticklabels(new_x_labels, rotation=60) grid.axes_llc.set_yticklabels(new_y_labels) grid.axes_llc.set_xlabel("Easting (m)") grid.axes_llc.set_ylabel("Northing (m)") plt.show()
def BasicDrapedPlotGridPlot(FileName, DrapeName, thiscmap='gray', drape_cmap='gray', colorbarlabel='Elevation in meters', clim_val=(0, 0), drape_alpha=0.6, FigFileName='Image.pdf', FigFormat='show'): print "======================================" print "Yo, I'm doing a draped plot" print FigFileName print FigFormat print "======================================" import matplotlib.pyplot as plt import matplotlib.lines as mpllines from mpl_toolkits.axes_grid1 import AxesGrid label_size = 20 #title_size = 30 axis_size = 28 # Set up fonts for plots rcParams['font.family'] = 'sans-serif' rcParams['font.sans-serif'] = ['arial'] rcParams['font.size'] = label_size # get the data raster = LSDMap_IO.ReadRasterArrayBlocks(FileName) raster_drape = LSDMap_IO.ReadRasterArrayBlocks(DrapeName) # now get the extent extent_raster = LSDMap_IO.GetRasterExtent(FileName) x_min = extent_raster[0] x_max = extent_raster[1] y_min = extent_raster[2] y_max = extent_raster[3] # make a figure, sized for a ppt slide fig = plt.figure(1, facecolor='white', figsize=(10, 7.5)) gs = plt.GridSpec(100, 75, bottom=0.1, left=0.1, right=0.9, top=1.0) ax = fig.add_subplot(gs[10:100, 10:75]) #grid = AxesGrid(fig, 111, # nrows_ncols=(1, 1), # axes_pad=(0.45, 0.15), # label_mode="1", # share_all=True, # cbar_location="right", # cbar_mode="each", # cbar_size="7%", # cbar_pad="2%", # ) # now get the tick marks n_target_tics = 5 xlocs, ylocs, new_x_labels, new_y_labels = GetTicksForUTM( FileName, x_max, x_min, y_max, y_min, n_target_tics) print "xmax: " + str(x_max) print "xmin: " + str(x_min) print "ymax: " + str(y_max) print "ymin: " + str(y_min) im = ax.imshow(raster[::-1], thiscmap, extent=extent_raster, interpolation="nearest") #im = grid[0].imshow(raster, thiscmap, interpolation="nearest") cbar = plt.colorbar(im) cbar.set_label(colorbarlabel) #cbar.set_height(1) #cbar = fig.cbar_axes[0].colorbar(im) #cbar.set_label_text(colorbarlabel) # set the colour limits print "Setting colour limits to " + str(clim_val[0]) + " and " + str( clim_val[1]) if (clim_val == (0, 0)): print "I don't think I should be here" im.set_clim(0, np.max(raster)) else: print "Now setting colour limits to " + str( clim_val[0]) + " and " + str(clim_val[1]) im.set_clim(clim_val[0], clim_val[1]) # Now for the drape: it is in grayscape im = ax.imshow(raster_drape[::-1], drape_cmap, extent=extent_raster, alpha=drape_alpha, interpolation="nearest") ax.spines['top'].set_linewidth(2.5) ax.spines['left'].set_linewidth(2.5) ax.spines['right'].set_linewidth(2.5) ax.spines['bottom'].set_linewidth(2.5) # This affects all axes because we set share_all = True. ax.set_xlim(x_min, x_max) ax.set_ylim(y_max, y_min) ax.set_xticks(xlocs) ax.set_yticks(ylocs) ax.set_xticklabels(new_x_labels, rotation=60) ax.set_yticklabels(new_y_labels) ax.set_xlabel("Easting (m)") ax.set_ylabel("Northing (m)") # This gets all the ticks, and pads them away from the axis so that the corners don't overlap ax.tick_params(axis='both', width=2.5, pad=10) for tick in ax.xaxis.get_major_ticks(): tick.set_pad(10) print "The figure format is: " + FigFormat if FigFormat == 'show': plt.show() else: plt.savefig(FigFileName, format=FigFormat) fig.clf()
def BasicChiPlotGridPlot(FileName, DrapeName, chi_csv_fname, thiscmap='gray', drape_cmap='gray', colorbarlabel='Elevation in meters', clim_val=(0, 0), drape_alpha=0.6, FigFileName='Image.pdf', FigFormat='show', elevation_threshold=0): import matplotlib.pyplot as plt import matplotlib.lines as mpllines from mpl_toolkits.axes_grid1 import AxesGrid from matplotlib import colors label_size = 10 #title_size = 30 axis_size = 12 # Set up fonts for plots rcParams['font.family'] = 'sans-serif' rcParams['font.sans-serif'] = ['arial'] rcParams['font.size'] = label_size #plt.rc('text', usetex=True) # get the data raster = LSDMap_IO.ReadRasterArrayBlocks(FileName) raster_drape = LSDMap_IO.ReadRasterArrayBlocks(DrapeName) # now get the extent extent_raster = LSDMap_IO.GetRasterExtent(FileName) x_min = extent_raster[0] x_max = extent_raster[1] y_min = extent_raster[2] y_max = extent_raster[3] # make a figure, sized for a ppt slide fig = plt.figure(1, facecolor='white', figsize=(4.92126, 3.5)) gs = plt.GridSpec(100, 100, bottom=0.25, left=0.1, right=1.0, top=1.0) ax = fig.add_subplot(gs[25:100, 10:95]) # This is the axis for the colorbar ax2 = fig.add_subplot(gs[10:15, 15:70]) #grid = AxesGrid(fig, 111, # nrows_ncols=(1, 1), # axes_pad=(0.45, 0.15), # label_mode="1", # share_all=True, # cbar_location="right", # cbar_mode="each", # cbar_size="7%", # cbar_pad="2%", # ) # now get the tick marks n_target_tics = 5 xlocs, ylocs, new_x_labels, new_y_labels = LSDMap_BP.GetTicksForUTM( FileName, x_max, x_min, y_max, y_min, n_target_tics) print "xmax: " + str(x_max) print "xmin: " + str(x_min) print "ymax: " + str(y_max) print "ymin: " + str(y_min) #Z1 = np.array(([0, 1]*4 + [1, 0]*4)*4) #Z1.shape = (8, 8) # chessboard #im2 = ax.imshow(Z1, cmap=plt.cm.gray, interpolation='nearest', # extent=extent_raster) #plt.hold(True) im1 = ax.imshow(raster[::-1], thiscmap, extent=extent_raster, interpolation="nearest") # set the colour limits print "Setting colour limits to " + str(clim_val[0]) + " and " + str( clim_val[1]) if (clim_val == (0, 0)): print "Im setting colour limits based on minimum and maximum values" im1.set_clim(0, np.max(raster)) else: print "Now setting colour limits to " + str( clim_val[0]) + " and " + str(clim_val[1]) im1.set_clim(clim_val[0], clim_val[1]) plt.hold(True) # Now for the drape: it is in grayscale #print "drape_cmap is: "+drape_cmap im3 = ax.imshow(raster_drape[::-1], drape_cmap, extent=extent_raster, alpha=drape_alpha, interpolation="nearest") # Set the colour limits of the drape im3.set_clim(0, np.max(raster_drape)) ax.spines['top'].set_linewidth(1) ax.spines['left'].set_linewidth(1) ax.spines['right'].set_linewidth(1) ax.spines['bottom'].set_linewidth(1) #ax.spines['bottom'].set_capstyle('projecting') #for spine in ax.spines.values(): # spine.set_capstyle('projecting') ax.set_xticklabels(new_x_labels, rotation=60) ax.set_yticklabels(new_y_labels) ax.set_xlabel("Easting (m)") ax.set_ylabel("Northing (m)") # This gets all the ticks, and pads them away from the axis so that the corners don't overlap ax.tick_params(axis='both', width=1, pad=2) for tick in ax.xaxis.get_major_ticks(): tick.set_pad(2) # Now we get the chi points EPSG_string = LSDMap_IO.GetUTMEPSG(FileName) print "EPSG string is: " + EPSG_string thisPointData = LSDMap_PD.LSDMap_PointData(chi_csv_fname) thisPointData.ThinData('elevation', elevation_threshold) # convert to easting and northing [easting, northing] = thisPointData.GetUTMEastingNorthing(EPSG_string) # The image is inverted so we have to invert the northing coordinate Ncoord = np.asarray(northing) Ncoord = np.subtract(extent_raster[3], Ncoord) Ncoord = np.add(Ncoord, extent_raster[2]) M_chi = thisPointData.QueryData('m_chi') #print M_chi M_chi = [float(x) for x in M_chi] # make a color map of fixed colors this_cmap = colors.ListedColormap( ['#2c7bb6', '#abd9e9', '#ffffbf', '#fdae61', '#d7191c']) bounds = [0, 50, 100, 175, 250, 1205] norm = colors.BoundaryNorm(bounds, this_cmap.N) sc = ax.scatter(easting, Ncoord, s=0.5, c=M_chi, cmap=this_cmap, norm=norm, edgecolors='none') # This affects all axes because we set share_all = True. ax.set_xlim(x_min, x_max) ax.set_ylim(y_max, y_min) ax.set_xticks(xlocs) ax.set_yticks(ylocs) cbar = plt.colorbar(sc, cmap=this_cmap, norm=norm, spacing='uniform', ticks=bounds, boundaries=bounds, orientation='horizontal', cax=ax2) cbar.set_label(colorbarlabel, fontsize=10) ax2.set_xlabel(colorbarlabel, fontname='Arial', labelpad=-35) print "The figure format is: " + FigFormat if FigFormat == 'show': plt.show() elif FigFormat == 'return': return fig else: plt.savefig(FigFileName, format=FigFormat, dpi=500) fig.clf()
def BasicDensityPlot(FileName, thiscmap='gray', colorbarlabel='Elevation in meters', clim_val=(0, 0)): import matplotlib.pyplot as plt import matplotlib.lines as mpllines label_size = 20 #title_size = 30 axis_size = 28 # Set up fonts for plots rcParams['font.family'] = 'sans-serif' rcParams['font.sans-serif'] = ['arial'] rcParams['font.size'] = label_size # get the data raster = LSDMap_IO.ReadRasterArrayBlocks(FileName) # now get the extent extent_raster = LSDMap_IO.GetRasterExtent(FileName) x_min = extent_raster[0] x_max = extent_raster[1] y_min = extent_raster[2] y_max = extent_raster[3] # make a figure, sized for a ppt slide fig = plt.figure(1, facecolor='white', figsize=(10, 7.5)) # make room for the colorbar #fig.subplots_adjust(bottom=0.1) #fig.subplots_adjust(top=0.9) #fig.subplots_adjust(left=0.2) #fig.subplots_adjust(right=0.8) ax1 = fig.add_subplot(1, 1, 1) im = ax1.imshow(raster[::-1], thiscmap, extent=extent_raster) print "The is the extent raster data element" print extent_raster print "now I am in the mapping routine" print "x_min: " + str(x_min) print "x_max: " + str(x_max) print "y_min: " + str(y_min) print "y_max: " + str(y_max) # now get the tick marks n_target_tics = 5 xlocs, ylocs, new_x_labels, new_y_labels = GetTicksForUTM( FileName, x_max, x_min, y_max, y_min, n_target_tics) plt.xticks(xlocs, new_x_labels, rotation=60) #[1:-1] skips ticks where we have no data plt.yticks(ylocs, new_y_labels) print "The x locs are: " print xlocs print "The x labels are: " print new_x_labels # some formatting to make some of the ticks point outward for line in ax1.get_xticklines(): line.set_marker(mpllines.TICKDOWN) #line.set_markeredgewidth(3) for line in ax1.get_yticklines(): line.set_marker(mpllines.TICKLEFT) #line.set_markeredgewidth(3) plt.xlim(x_min, x_max) plt.ylim(y_max, y_min) plt.xlabel('Easting (m)', fontsize=axis_size) plt.ylabel('Northing (m)', fontsize=axis_size) ax1.set_xlabel("Easting (m)") ax1.set_ylabel("Northing (m)") # set the colour limits print "Setting colour limits to " + str(clim_val[0]) + " and " + str( clim_val[1]) if (clim_val == (0, 0)): print "I don't think I should be here" im.set_clim(0, np.max(raster)) else: print "Now setting colour limits to " + str( clim_val[0]) + " and " + str(clim_val[1]) im.set_clim(clim_val[0], clim_val[1]) cbar = fig.colorbar(im, orientation='vertical') cbar.set_label(colorbarlabel) #plt.tight_layout() plt.show()
def DrapedOverHillshade(FileName, DrapeName, thiscmap='gray', drape_cmap='gray', colorbarlabel='Elevation in meters', clim_val=(0, 0), drape_alpha=0.6, ShowColorbar=False, ShowDrapeColorbar=False, drape_cbarlabel=None): import matplotlib.pyplot as plt import matplotlib.lines as mpllines from mpl_toolkits.axes_grid1 import AxesGrid, make_axes_locatable label_size = 20 #title_size = 30 axis_size = 28 # Set up fonts for plots rcParams['font.family'] = 'sans-serif' rcParams['font.sans-serif'] = ['arial'] rcParams['font.size'] = label_size hillshade = Hillshade(FileName) #hillshade = LSDMap_IO.ReadRasterArrayBlocks(DrapeName) # DAV - option to supply array directly (after masking for example, rather # than reading directly from a file. Should not break anyone's code) # (You can't overload functions in Python...) if isinstance(DrapeName, str): raster_drape = LSDMap_IO.ReadRasterArrayBlocks(DrapeName) elif isinstance(DrapeName, np.ndarray): raster_drape = DrapeName else: print "DrapeName supplied is of type: ", type(DrapeName) raise ValueError('DrapeName must either be a string to a filename, \ or a numpy ndarray type. Please try again.') # now get the extent extent_raster = LSDMap_IO.GetRasterExtent(FileName) x_min = extent_raster[0] x_max = extent_raster[1] y_min = extent_raster[2] y_max = extent_raster[3] # make a figure, sized for a ppt slide fig = plt.figure(1, facecolor='white', figsize=(10, 7.5)) if ShowColorbar: grid = AxesGrid( fig, 111, nrows_ncols=(1, 1), axes_pad=(0.45, 0.15), label_mode="1", share_all=True, cbar_location="right", cbar_mode="each", cbar_size="7%", cbar_pad="2%", ) #ShowDrapeColorbar = True #if ShowDrapeColorbar and ShowColorbar: #divider = make_axes_locatable(fig) #cax = divider.append_axes("right", size = "5%", pad=0.05) else: grid = AxesGrid( fig, 111, nrows_ncols=(1, 1), axes_pad=(0.45, 0.15), label_mode="1", share_all=True, ) # now get the tick marks n_target_tics = 5 xlocs, ylocs, new_x_labels, new_y_labels = GetTicksForUTM( FileName, x_max, x_min, y_max, y_min, n_target_tics) print "xmax: " + str(x_max) print "xmin: " + str(x_min) print "ymax: " + str(y_max) print "ymin: " + str(y_min) im = grid[0].imshow(hillshade[::-1], thiscmap, extent=extent_raster, interpolation="nearest") #im = grid[0].imshow(raster, thiscmap, interpolation="nearest") if ShowColorbar: cbar = grid.cbar_axes[0].colorbar(im) cbar.set_label_text(colorbarlabel) # set the colour limits print "Setting colour limits to " + str(clim_val[0]) + " and " + str( clim_val[1]) if (clim_val == (0, 0)): print "I don't think I should be here" im.set_clim(0, np.max(hillshade)) else: print "Now setting colour limits to " + str( clim_val[0]) + " and " + str(clim_val[1]) im.set_clim(clim_val[0], clim_val[1]) # Now for the drape: it is in grayscape im2 = grid[0].imshow(raster_drape[::-1], drape_cmap, extent=extent_raster, alpha=drape_alpha, interpolation="nearest") if ShowDrapeColorbar: cbar2 = grid.cbar_axes[0].colorbar(im2) cbar2.set_label_text(drape_cbarlabel) #plt.colorbar(im) # This affects all axes because we set share_all = True. grid.axes_llc.set_xlim(x_min, x_max) grid.axes_llc.set_ylim(y_max, y_min) grid.axes_llc.set_xticks(xlocs) grid.axes_llc.set_yticks(ylocs) grid.axes_llc.set_xticklabels(new_x_labels, rotation=60) grid.axes_llc.set_yticklabels(new_y_labels) grid.axes_llc.set_xlabel("Easting (m)") grid.axes_llc.set_ylabel("Northing (m)") plt.show()