def colorregions(region): """Set the colors to ensure a uniform scheme for each region """ d={} d["ALL"]="k" d["NHDA"]=cm.gray(.5) d["NADA"]=cm.Purples(.5) d["OWDA"]=cm.Blues(.5) d["MXDA"]=cm.PiYG(.1) d["ANZDA"]=cm.PiYG(.8) d["MADA"]=cm.Oranges(.5) d["GDA"]="k" return d[region]
def get_dataset_color(dataset,depth=None): """Set the colors to ensure a uniform scheme for each dataset """ dataset=string.lower(dataset) d={} d["dai"]=cm.Blues(.5) d["tree"]=cm.summer(.3) d["cru"]=cm.Blues(.9) #models d["picontrol"]=cm.Purples(.8) d["h85"]="k" d["tree_noise"]=cm.PiYG(.2) #Soil moisture d["merra2"]={} d["merra2"]["30cm"]=cm.copper(.3) d["merra2"]["2m"]=cm.copper(.3) d["gleam"]={} d["gleam"]["30cm"]=cm.Reds(.3) d["gleam"]["2m"]=cm.Reds(.7) if depth is None: return d[dataset] else: return d[dataset][depth]
backupCount=3) # file handler fh.setLevel(logging.DEBUG) ch = logging.StreamHandler() # console handler ch.setLevel(logging.DEBUG) formatter = logging.Formatter( '%(asctime)s - %(name)s - %(levelname)s - %(message)s') ch.setFormatter(formatter) fh.setFormatter(formatter) logger.addHandler(fh) logger.addHandler(ch) logger.info('Initializing %s', __name__) colors = [ cm.RdBu(0.85), cm.RdBu(0.7), cm.PiYG(0.7), cm.Spectral(0.38), cm.Spectral(0.25) ] if __name__ == '__main__': # parameter setting gps_dir = s.GPS_DIR gps_counter_file = s.GPS_COUNTER_FILE TWEET_COUNTER_FILE = s.TWEET_COUNTER_FILE timestart = s.TIMESTART timestart_text = s.TIMESTART_TEXT timeend = s.TIMEEND timeend_text = s.TIMEEND_TEXT aoi = s.AOI unit_temporal = s.UNIT_TEMPORAL
rys_expected_sig_from_sib.append(rys_total_signal*(sib_sig_d['nonchr']/sib_total_signal)) sib_posn_dif_from_expected.append((sib_posn_d['nonchr']-sib_expected_pos_d['nonchr'])/sib_expected_pos_d['nonchr']) sib_sig_dif_from_expected.append((sib_sig_d['nonchr']-sib_expected_sig_d['nonchr'])/sib_expected_sig_d['nonchr']) rys_posn_dif_from_sib.append((rys_posn_d['nonchr']-rys_expected_posn_from_sib[25])/rys_expected_posn_from_sib[25]) rys_sig_dif_from_sib.append((rys_sig_d['nonchr']-rys_expected_sig_from_sib[25])/rys_expected_sig_from_sib[25]) #!!sib nonchromosomal signal is blown out relative to other scaffolds. store value and annotate, color separately NC_sig_dif = sib_sig_dif_from_expected[25] sib_sig_dif_from_expected[25] = 0 #build proportional difference color arrays sib_norm = colors.Normalize(vmin=-abs(max(sib_posn_dif_from_expected+sib_sig_dif_from_expected, key=abs)), vmax=abs(max(sib_posn_dif_from_expected+sib_sig_dif_from_expected, key=abs))) rys_norm = colors.Normalize(vmin=-abs(max(rys_posn_dif_from_sib+rys_sig_dif_from_sib, key=abs)), vmax=abs(max(rys_posn_dif_from_sib+rys_sig_dif_from_sib, key=abs))) sib_pos_colors = cm.PiYG(sib_norm(sib_posn_dif_from_expected)) sib_sig_colors = cm.PiYG(sib_norm(sib_sig_dif_from_expected)) sib_sig_colors[25] = [0, .1, 1, 1] rys_pos_colors = cm.PRGn(rys_norm(rys_posn_dif_from_sib)) rys_sig_colors = cm.PRGn(rys_norm(rys_sig_dif_from_sib)) #build figure fig = plt.figure(figsize=(6,6.5)) gs1 = GridSpec (2,2, wspace=.1, hspace=.05, left=.05, right=.95, top=.95, bottom=.15) pos_sib = plt.subplot(gs1[0, 0]) pos_rys = plt.subplot(gs1[0, 1]) sig_sib = plt.subplot(gs1[1, 0]) sig_rys = plt.subplot(gs1[1, 1]) pos_sib.set_ylabel('Positions', fontsize=12, weight='bold')
fig2 = plt.figure("y") plt.clf() plt.subplots_adjust(right=0.75) fig3 = plt.figure("z") plt.clf() plt.subplots_adjust(right=0.75) # Loop thru particles count = 0 for particle_id in particle_ids: count = count + 1 particle_data = partextract(extract_exe, work_dir, uda_name, plot_dir, particle_id[0], error_file) plt_color = cm.PiYG(float(count) / float(len(particle_ids))) particle_pos = "Sim: (%0.3f, %0.3f)" % (float( particle_id[1]), float(particle_id[2])) plot_x(particle_data, particle_pos, plt_color, '-') plot_y(particle_data, particle_pos, plt_color, '-') plot_z(particle_data, particle_pos, plt_color, '-') pos_all = exact_solution() count = 0 for pos in pos_all: count = count + 1 plt_color = cm.winter(float(count) / float(len(pos_all))) particle_pos = "Exact: (%0.3f,%0.3f)" % (pos[0][1], pos[0][2]) plot_x(pos, particle_pos, plt_color, '--') plot_y(pos, particle_pos, plt_color, '--') plot_z(pos, particle_pos, plt_color, '--')
# Get the locations of the detector (change if needed) positions = getPositions(x, y, z, radii, theta, phi) print positions data_file = os.path.join(plot_dir, uda_name + "_acc.data") fid = open(data_file, 'w+') for idx, pos in enumerate(positions): xpos = pos[0] ypos = pos[1] zpos = pos[2] rad = np.sqrt((x - xpos) * (x - xpos) + (y - ypos) * (y - ypos) + (z - zpos) * (z - zpos)) data = timeextract(extract_exe, work_dir, plot_dir, uda_name, xpos, ypos, zpos, material_id) plt_color = cm.PiYG(float(idx) / float(len(positions))) line_style = '-' plot_acc('x-acc', data, 'x', rad, plt_color, line_style) plot_acc('y-acc', data, 'y', rad, plt_color, line_style) plot_acc('z-acc', data, 'z', rad, plt_color, line_style) for timedata in data: fid.write( '%s %s %s %s %s %s %s %s %s %s %s\n' % (xpos, ypos, zpos, rad, timedata[0], timedata[1], timedata[2], timedata[3], timedata[4], timedata[5], timedata[6])) fid.close() plt.figure('x-acc') plt.legend(bbox_to_anchor=(1.05, 1), loc=2, prop={'size': 10}) plt.figure('y-acc')
#!/usr/bin/env python # coding: utf-8 # In[2]: import matplotlib.pyplot as plt import matplotlib.cm as cm import numpy as np fig, (ax1, ax2, ax3, ax4, ax5, ax6, ax7) = plt.subplots(nrows=7, sharex=True) x = np.linspace(0, 2 * np.pi, 100) for i in range(30): y = i * np.sin(x) ax1.plot(x, y, color=cm.rainbow(i / 30.0)) ax2.plot(x, y, color=cm.Reds(i / 30.0)) ax3.plot(x, y, color=cm.binary(i / 30.0)) ax4.plot(x, y, color=cm.PiYG(i / 30.0)) ax5.plot(x, y, color=cm.twilight(i / 30.0)) ax6.plot(x, y, color=cm.Pastel1(i / 30.0)) ax7.plot(x, y, color=cm.flag(i / 30.0)) ax1.set_xlim(0, 2 * np.pi) fig.show() # In[ ]:
print(N_ITERATIONS, REG_COEFF) fin = open(f'../../results/dataset_size/SICK/reg_coeff_{REG_COEFF}_it_{N_ITERATIONS}.txt', 'r') accs[i, :] = np.array([float(line.strip().split(' ')[0]) for line in fin]) * 100 plt.errorbar(x_axis, np.mean(accs, axis=1), yerr=np.std(accs, axis=1), color='k', linestyle='--', label='SICK uncleaned') for c, DATASET in enumerate(['RNN-priming-short-500', 'RNN-priming-short-1000', 'RNN-priming-short-5000', 'RNN-priming-short-10000']): for s, N_ITERATIONS in enumerate([1, 2, 5, 10]): accs = np.zeros((len(x_axis), N_SAMPLES)) for i, REG_COEFF in enumerate(REG_COEFFS): fin = open('../../results/dataset_size/' + DATASET + f'/reg_coeff_{REG_COEFF}_it_{N_ITERATIONS}.txt', 'r') accs[i, :] = np.array([float(line.strip().split(' ')[-1]) for line in fin]) * 100 sent_count = DATASET.split('-')[-1] plt.errorbar(x_axis, np.mean(accs, axis=1), yerr=np.std(accs, axis=1), c=cm.prism((3-c)*10), linestyle=styles[s], label=f'SICK cleaned by RNN-{sent_count} at {N_ITERATIONS} it') print(cm.PiYG(0), cm.PiYG(100)) plt.xticks(x_axis, x_labels) plt.ylim((50, 100)) plt.xlabel('Inverse regularization strength C') plt.ylabel('accuracy (%)') plt.legend(loc='lower left', bbox_to_anchor=(0, 0), shadow=True, fontsize='x-small') plt.grid(True) plt.show()
print(df_city_main_count) df_city_main_count['gsmc'] = df_city_main_count['gsmc'] / ( df_city_main_count['gsmc'].sum()) df_city_main_count.columns = ['number', 'percentage', 'ad'] # print(df_city_main_count) df_city_main_count['label'] = df_city_main_count.index + ' ' + ( (df_city_main_count['percentage'] * 100).round()).astype('int').astype('str') + '%' # print(type(d label = df_city_main_count['label'] sizes = df_city_main_count['number'] # 设置绘图区域大小 fig, axes = plt.subplots(figsize=(10, 6), ncols=2) ax1, ax2 = axes.ravel() colors = cm.PiYG(np.arange(len(sizes)) / len(sizes)) # colormaps: Paired, autumn, rainbow, gray,spring,Darks# # 由于城市数量太多,饼图中不显示labels和百分比 patches, texts = ax1.pie(sizes, labels=None, shadow=False, startangle=0, colors=colors) ax1.axis('equal') ax1.set_title('城市分布', loc='center') # ax2 只显示图例(legend) ax2.axis('off') ax2.legend(patches, label, loc='center left', fontsize=9) plt.savefig('job_distribute.jpg')
size=22, va="baseline", ha="left", fontweight='medium', color='#343837') #plt.title(model.upper(), fontsize=22) plt.savefig('%s/wsi_ssp2_2010s_%s_7plants.pdf' % (dir_fig, model)) plt.show() ### WSI relative change map var_min = -90 var_max = 90 bnd = np.linspace(var_min, var_max, 10) ### 10 ticks on the colorbar, should be even cmap_div = custom_div_cmap(numcolors=11, mincol=cm.PiYG(255), maxcol=cm.PiYG(0), midcol='#f0f0f0') ### for contribution norm = colors.BoundaryNorm(bnd, cmap_div.N) ticks = np.linspace(var_min, var_max, 10) imshow_Pakistan(wsi_ratio[::-1], vmin=var_min, vmax=var_max, norm=norm, cmap=cmap_div, ticks=ticks, fig_name='wsi_ssp2_changes_2050s_2010s_7plants') ### WSI trend map sig_mask = np.ma.masked_greater_equal(pva_ssp2, 0.05).mask
print("# width_out = " + str(np.round(p84_out, 2) - np.round(p16_out, 2))) ### plot figure = plt.figure(figsize=(10, 2)) gs = gridspec.GridSpec(nrows=8, ncols=17) plt.subplots_adjust(bottom=0.22, left=0.05, right=0.98, top=0.88) ax1 = plt.subplot(gs[0:8, 0:8]) ax2 = plt.subplot(gs[0:8, 9:17]) ax1.grid(axis="x") ax2.grid(axis="both") plt.rcParams["font.size"] = 11 plt.rcParams["legend.fontsize"] = 9 # ax1 ylim = [0.0001, np.r_[y_in, y_out].max() * 1.4] ax1.step(x_in, y_in, color=cm.PiYG(1 / 1.), lw=1, alpha=1.0, where="mid") ax1.bar(x_in, y_in, lw=0, color=cm.PiYG(1 / 1.), alpha=0.2, width=x_in[1] - x_in[0], align="center", label="inside mask") ax1.plot(p50_in_norm, ylim[1] * 0.95, "o", markeredgewidth=0, c=cm.PiYG(1 / 1.), markersize=7, zorder=1)