def plot_1ddists_1(cosm_params_dict, latex_params_dict): for param_name, params_value in cosm_params_dict.iteritems(): params_lb_value = params_lims_dict[param_name][0] params_ub_value = params_lims_dict[param_name][1] latex_param_name = latex_params_dict[param_name] pdf_ins = get_1d_pdf(params_value, params_lb_value, params_ub_value) pdf_ins.set_sigma_level() pdf_ins.prepare_histogram_from_subdivision_ext(cut_off=0, bins_number=20) pdf_ins.prepare_get_interpolated_1d_distr() plt.plot(pdf_ins.x, pdf_ins.get_interpolated_1d_distr(pdf_ins.x), '-', color='black', linewidth=3) plt.xlabel(latex_param_name, {'fontsize': 20}) plt.ylim(0.0, 1.2) plt.xlim(params_lb_value, params_ub_value) plt.tight_layout( pad=0.1) # Make the figure use all available whitespace figname = param_name + "_1d" + ".pdf" plt.savefig(figname) plt.cla()
def set_data_to_plot(self, params_dict, params_lims_dict, params_latex_dict): list_of_names = params_dict.keys() print(list_of_names) product_list = map(list, product(list_of_names, repeat=2)) for pair in product_list: row = list_of_names.index(pair[0]) column = list_of_names.index(pair[1]) self.file_desc.write("unset xlabel\n") self.file_desc.write("unset ylabel\n") if (row == (len(list_of_names) - 1)): if (row == column): self.file_desc.write("unset ylabel\n") self.file_desc.write("set xlabel \'" + str(params_latex_dict[pair[1]]) + "\'\n") if (column == 0): self.file_desc.write("set ylabel \'" + str(params_latex_dict[pair[0]]) + "\'\n") if (row < column): self.file_desc.write("set multiplot next\n\n") continue if (pair[0] == pair[1]): self.file_desc.write("set xrange [" + str(params_lims_dict[pair[0]][0]) + ":" + str(params_lims_dict[pair[0]][1]) + "]\n") self.file_desc.write("set yrange [0:1.1]\n") filename = str(row) + "-1d.dat" pdf_ins = get_1d_pdf(params_dict[pair[0]], params_lims_dict[pair[0]][0], \ params_lims_dict[pair[0]][1]) pdf_ins.set_sigma_level() pdf_ins.prepare_histogram_from_subdivision(cut_off=0, bins_number=60) pdf_ins.prepare_get_interpolated_1d_distr() x_data = pdf_ins.x y_data = pdf_ins.get_interpolated_1d_distr(pdf_ins.x) below_zero = np.where(y_data < 0) y_data[below_zero] = 0.0 np.savetxt(filename, np.c_[x_data, y_data], fmt='%12.5e') self.file_desc.write("plot \'" + str(filename) + "\' u 1:2 notitle with lines" \ " ls 1 \n\n") else: self.file_desc.write("set xrange [" + str(params_lims_dict[pair[1]][0]) + ":" + str(params_lims_dict[pair[1]][1]) + "]\n") self.file_desc.write("set yrange [" + str(params_lims_dict[pair[0]][0]) + ":" + str(params_lims_dict[pair[0]][1]) + "]\n") filename = str(row) + "-vs-" + str(column) + "-2d.dat" contour_ins = get_2d_posterior(params_dict[pair[0]], params_dict[pair[1]]) contour_ins.prepare_contour() np.savetxt(filename, np.c_[params_dict[pair[1]][::50], params_dict[pair[0]][::50]], fmt='%12.5e') self.file_desc.write("plot \'" + str(filename) + "\' u 1:2 notitle w p" \ " ls 2, \\\n") filename_1_sigma = str(row) + "-vs-" + str( column) + "-1-sigma.dat" filename_2_sigma = str(row) + "-vs-" + str( column) + "-2-sigma.dat" np.savetxt(filename_1_sigma, np.c_[contour_ins.y_vert_1_s, contour_ins.x_vert_1_s], fmt='%12.5e') np.savetxt(filename_2_sigma, np.c_[contour_ins.y_vert_2_s, contour_ins.x_vert_2_s], fmt='%12.5e') self.file_desc.write("\'" + str(filename_1_sigma) + "\' u 1:2 notitle w lines" \ " ls 1, \\\n") self.file_desc.write("\'" + str(filename_2_sigma) + "\' u 1:2 notitle w lines" \ " ls 1\n\n") self.file_desc.write("unset multiplot\n") self.file_desc.close()