def plot_data(data = None, imagefile = 'image.png', units = 'm**3/s', minmax = (None, None), indices_file = 'data/streamflows/hydrosheds_euler9/aex_discharge_1970_01_01_00_00.nc', color_map = mpl.cm.get_cmap('RdBu', 20), ticks_locator = LinearLocator(), i_list = None, j_list = None, title = ''): if imagefile != None: plt.clf() if i_list == None or j_list == None: i_list, j_list = data_select.get_indices_from_file(indices_file) to_plot = np.ma.masked_all(xs.shape) for i, j, value in zip(i_list, j_list, data): to_plot[i, j] = value plt.title(title) plt.pcolormesh(xs,ys,to_plot.copy(), cmap = color_map, edgecolors = 'None', antialiased = True, vmin = minmax[0], vmax = minmax[1]) m.drawcoastlines() boundaries.plot_basin_boundaries_from_shape(m, plotter = plt, linewidth = 0.5) draw_meridians_and_parallels(m, 10) # plot_directions(data_mask = to_plot) cb = plt.colorbar(ticks = ticks_locator, format = "%.1f") cb.ax.set_ylabel(units) ymin, ymax = plt.ylim() plt.ylim(ymin + 0.05 * (ymax - ymin) , ymax * 0.25) # xmin, xmax = plt.xlim() plt.xlim(xmin + (xmax - xmin) * 0.55, 0.72*xmax) if imagefile != None: plt.savefig(imagefile, bbox_inches = 'tight')
def plot_naveed_troubled_points(path = 'data/data_txt_naveed/TroubledGridCells_AtLeast3Sims.csv'): f = open(path) lines = f.readlines() if len(lines) == 1: lines = lines[0].split('\r') f.close() #skip header while len(lines) > 0: line = lines.pop(0) if 'stationsri' in line.lower(): break print(lines) folder_path = 'data/streamflows/hydrosheds_euler9/' i_indices, j_indices = data_select.get_indices_from_file(folder_path + 'aex_discharge_1970_01_01_00_00.nc') cols = [1,2,3] names = ['C', 'F', 'Both'] color_map = ListedColormap(['r','b', 'g']) #plt.subplots_adjust(hspace = 0.0001) for c, name in zip(cols, names): plt.subplot(2,2,c) to_plot = np.ma.masked_all(xs.shape) data = get_column(c, lines) print(data) for i, j, v in zip(i_indices, j_indices, data): if v: #no color for 0 to_plot[i, j] = v else: to_plot[i, j] = 3 basemap.pcolormesh(xs, ys, to_plot.copy(), cmap = color_map, shading = 'flat', rasterized = False ) plot_basin_boundaries_from_shape(basemap, plotter = plt, linewidth = 1, edge_color = 'k') basemap.drawcoastlines(linewidth = 0.5) plot_utils.draw_meridians_and_parallels(basemap, step_degrees = 30) plt.title(name) ymin, ymax = plt.ylim() plt.ylim(ymin + 0.05 * (ymax - ymin) , ymax * 0.25) xmin, xmax = plt.xlim() plt.xlim(xmin + (xmax - xmin) * 0.55, 0.72*xmax) cb = plt.colorbar(shrink = 0.5, format = '%d') cb.set_ticks([1.25, 2, 2.75]) cb.set_ticklabels([1,2,3]) plt.savefig('TroubledGridCells_AtLeast3Sims.pdf', bbox_inches = 'tight') pass