def test_uni_plot_one_plot(self): # uni plot aplot_2 = APlot() aplot_2.uni_plot(0, self.xx, self.yy) aplot_2.tight_layout() self.image_name = "image_uniplot_1" self.check_plot()
def test_uni_plot_ax_bis(self): # two plots same figures aplot_1 = APlot() aplot_1.uni_plot(0, self.xx, self.yy + 5) aplot_1.uni_plot_ax_bis(0, self.xx, np.exp(self.xx)) self.image_name = "image_plot_bis" self.check_plot()
def test_bi_plot(self): aplot_4 = APlot(how=(2, 2)) aplot_4.bi_plot(0, 1, self.xx, self.yy, self.xx, self.yy) aplot_4.uni_plot(2, self.xx, self.yy) aplot_4.uni_plot(3, self.xx, self.yy) aplot_4.tight_layout() self.image_name = "image_biplot" self.check_plot()
def test_uni_plot_for_plots_same_graph_sharey(self): # uni plot *4 aplot_3 = APlot(how=(2, 2), sharey=True) aplot_3.uni_plot(0, self.xx, self.yy) aplot_3.uni_plot(1, self.xx, self.yy) aplot_3.uni_plot(2, self.xx, self.yy) aplot_3.uni_plot(3, self.xx, self.yy) aplot_3.tight_layout() self.image_name = "image_uniplot_2_sharey" self.check_plot()
def test_show_legend_for_two_axis(self): yy = np.abs(np.cos(self.xx)) + 1 # second, try the same as before where the second axis is also setting another characteristic. aplot = APlot() dict_plot1 = {'title': 'my title1'} dict_plot2 = {'title': 'my title2'} aplot.uni_plot(0, self.xx, yy, dict_ax=dict_plot1) aplot.uni_plot_ax_bis(0, self.xx, 3 * np.sin(self.xx) + 1, dict_ax=dict_plot2) aplot.show_legend() self.image_name = "image_legend_two_axis" self.check_plot()
def plot_parameters_respect_to_time_hawkes(self): # I m printing the evolution of the parameters there. aplot = APlot(how=(1, self.M)) tt = np.linspace(0, 1, 1000) my_colors = plt.cm.rainbow(np.linspace(0, 1, 2 * self.M)) for i_dim in range(self.M): xx_nu = [self.NU[i_dim](t, 1, 0) for t in tt] aplot.uni_plot(nb_ax=i_dim, yy=xx_nu, xx=tt, dict_plot_param={ "label": f"nu, {i_dim}", "color": "blue", "markersize": 0, "linewidth": 2 }, tight=False) color = iter(my_colors) for j_dim in range(self.M): c1 = next(color) c2 = next(color) xx_alpha = [self.ALPHA[i_dim][j_dim](t, 1, 0) for t in tt] xx_beta = [self.BETA[i_dim][j_dim](t, 1, 0) for t in tt] aplot.uni_plot(nb_ax=i_dim, yy=xx_alpha, xx=tt, dict_plot_param={ "label": f"alpha, {i_dim},{j_dim}.", "color": c1, "markersize": 0, "linewidth": 2 }, tight=False) aplot.uni_plot(nb_ax=i_dim, yy=xx_beta, xx=tt, dict_plot_param={ "label": f"beta, {i_dim},{j_dim}.", "color": c2, "markersize": 0, "linewidth": 2 }, tight=False) aplot.set_dict_fig( i_dim, { 'title': "Evolution of the parameters, time in % of total; dimension : {}" .format(i_dim), 'xlabel': '', 'ylabel': '' }) aplot.show_legend(i_dim)
def test_uni_plot_for_plots_same_graph_sharey_not_same_interval_for_y( self): xx = np.linspace(-1, 1, 1000) aplot_3 = APlot(how=(2, 2), sharey=True) aplot_3.uni_plot(0, xx, np.exp(xx)) aplot_3.uni_plot(1, xx + 1, np.exp(xx + 1)) aplot_3.uni_plot(2, xx + 1, np.exp(xx + 1)) aplot_3.uni_plot(3, xx, np.exp(xx)) aplot_3.tight_layout() self.image_name = "image_uniplot_2_sharey_not_same_interval_for_y" self.check_plot()
integral_of_pdf_2 = simps(values_density_of_SVI2, val_density) price_1 = compute_integral(val_density, values_density_of_SVI1) price_2 = compute_integral(val_density, values_density_of_SVI2) print("ST1 = ", price_1) print("ST2 = ", price_2) print("Relative Error between both prices: ", (price_2 - price_1) / min(price_2, price_1) * 100, "%") uu = np.linspace(1, 2, NB_OF_UU) densities_plot = APlot(how=(1, 1)) densities_plot.uni_plot(nb_ax=0, xx=val_density[::100], yy=values_density_of_SVI1[::100], dict_plot_param={ "color": "red", "label": "Density 1" }) densities_plot.uni_plot(nb_ax=0, xx=val_density[::100], yy=values_density_of_SVI2[::100], dict_plot_param={"label": "Density 2"}, dict_ax={ "title": "Densities", "xlabel": "Log Moneyness", "ylabel": "PDF" }) densities_plot.show_legend() true_vs_computed_TIV = APlot(how=(1, 1))
def test_set_dict_ax_and_bis_each_parameter_only_first_two_axis_same_graph( self): # first, trying every simple possibility for dict_ax yy = np.abs(np.cos(self.xx)) + 1 with self.subTest('title'): aplot = APlot() dict_plot = {'title': 'my title'} aplot.uni_plot(0, self.xx, yy, dict_ax=dict_plot) aplot.uni_plot_ax_bis(0, self.xx, 3 * np.sin(self.xx) + 1) self.image_name = "image_set_dict_ax_title" self.check_plot() with self.subTest('xlabel'): aplot = APlot() dict_plot = {'xlabel': 'my x label'} aplot.uni_plot(0, self.xx, yy, dict_ax=dict_plot) aplot.uni_plot_ax_bis(0, self.xx, 3 * np.sin(self.xx) + 1) self.image_name = "image_set_dict_ax_xlabel" self.check_plot() with self.subTest('ylabel'): aplot = APlot() dict_plot = {'ylabel': 'my y label'} aplot.uni_plot(0, self.xx, yy, dict_ax=dict_plot) aplot.uni_plot_ax_bis(0, self.xx, 3 * np.sin(self.xx) + 1) self.image_name = "image_set_dict_ax_ylabel" self.check_plot() with self.subTest('xscale'): aplot = APlot() dict_plot = {'xscale': 'log'} aplot.uni_plot(0, self.xx, yy, dict_ax=dict_plot) aplot.uni_plot_ax_bis(0, self.xx, 3 * np.sin(self.xx) + 1) self.image_name = "image_set_dict_ax_xscale_only_principal_axis" self.check_plot() with self.subTest('yscale left'): aplot = APlot() dict_plot = {'yscale': 'log'} aplot.uni_plot(0, self.xx, yy, dict_ax=dict_plot) aplot.uni_plot_ax_bis(0, self.xx, 3 * np.sin(self.xx) + 1) self.image_name = "image_set_dict_ax_yscale" self.check_plot() with self.subTest('xint'): aplot = APlot() dict_plot = {'xint': True} aplot.uni_plot(0, self.xx, yy, dict_ax=dict_plot) aplot.uni_plot_ax_bis(0, self.xx, 1 / 3 * np.sin(self.xx) + 1) self.image_name = "image_set_dict_ax_xint" self.check_plot() with self.subTest('xint_yint'): aplot = APlot() dict_plot = {'xint': True, 'yint': True} aplot.uni_plot(0, self.xx, yy, dict_ax=dict_plot) aplot.uni_plot_ax_bis(0, self.xx, 1 / 3 * np.sin(self.xx) + 1) self.image_name = "image_set_dict_ax_xyint" self.check_plot() for i in range(11): with self.subTest('parameter', i=i): aplot = APlot() dict_plot = { 'parameters': ['A', 3, 5] * i, 'name_parameters': ['A', '$\sigma$', '$\\rho$'] * i } aplot.uni_plot(0, self.xx, yy, dict_ax=dict_plot) aplot.uni_plot_ax_bis(0, self.xx, 3 * np.sin(self.xx) + 1) self.image_name = f"image_set_dict_ax_parameter_{i}" self.check_plot() # with self.subTest('parameters not good length'): # aplot = APlot() # # dict_plot = { # 'parameters': ['A', 3, 5, 10, 42], 'name_parameters': ['A']} # # aplot.uni_plot(0, self.xx, yy, dict_ax=dict_plot) # aplot.uni_plot_ax_bis(0, self.xx, 3 * np.sin(self.xx) + 1) with self.subTest('xlim'): aplot = APlot() dict_plot = {'xlim': [0, 0.5]} aplot.uni_plot(0, self.xx, yy, dict_ax=dict_plot) aplot.uni_plot_ax_bis(0, self.xx, 3 * np.sin(self.xx) + 1) self.image_name = "image_set_dict_ax_xlim" self.check_plot() with self.subTest('ylim'): aplot = APlot() dict_plot = {'ylim': [1.2, 2.4]} aplot.uni_plot(0, self.xx, yy, dict_ax=dict_plot) aplot.uni_plot_ax_bis(0, self.xx, 3 * np.sin(self.xx) + 1) self.image_name = "image_set_dict_ax_ylim" self.check_plot()
def test_set_dict_ax_and_bis_each_parameter_both_two_axis_same_graph(self): yy = np.abs(np.cos(self.xx)) + 1 # second, try the same as before where the second axis is also setting another characteristic. with self.subTest('two different titles'): aplot = APlot() dict_plot1 = {'title': 'my title1'} dict_plot2 = {'title': 'my title2'} aplot.uni_plot(0, self.xx, yy, dict_ax=dict_plot1) aplot.uni_plot_ax_bis(0, self.xx, 3 * np.sin(self.xx) + 1, dict_ax=dict_plot2) self.image_name = "image_set_dict_ax_title_2" self.check_plot() with self.subTest('two xlabels'): aplot = APlot() dict_plot1 = {'xlabel': 'my x label1'} dict_plot2 = {'xlabel': 'my x label2'} aplot.uni_plot(0, self.xx, yy, dict_ax=dict_plot1) aplot.uni_plot_ax_bis(0, self.xx, 3 * np.sin(self.xx) + 1, dict_ax=dict_plot2) self.image_name = "image_set_dict_ax_xlabel_2" self.check_plot() with self.subTest('two ylabels'): aplot = APlot() dict_plot1 = {'ylabel': 'my y label1'} dict_plot2 = {'ylabel': 'my y label2'} aplot.uni_plot(0, self.xx, yy, dict_ax=dict_plot1) aplot.uni_plot_ax_bis(0, self.xx, 3 * np.sin(self.xx) + 1, dict_ax=dict_plot2) self.image_name = "image_set_dict_ax_ylabel_2" self.check_plot() with self.subTest('xscale same both axis'): aplot = APlot() dict_plot = {'xscale': 'log'} aplot.uni_plot(0, self.xx, yy, dict_ax=dict_plot) aplot.uni_plot_ax_bis(0, self.xx, 3 * np.sin(self.xx) + 1, dict_ax=dict_plot) self.image_name = "image_set_dict_ax_xscale_both_same_scale" self.check_plot() with self.subTest('yscale same both axis'): aplot = APlot() dict_plot = {'yscale': 'log'} aplot.uni_plot(0, self.xx, yy, dict_ax=dict_plot) aplot.uni_plot_ax_bis(0, self.xx, 3 * np.sin(self.xx) + 1, dict_ax=dict_plot) self.image_name = "image_set_dict_ax_yscale_2_same" self.check_plot() with self.subTest('xscale different'): aplot = APlot() dict_plot2 = {'xscale': 'log'} dict_plot = {'xscale': 'linear'} aplot.uni_plot(0, self.xx, yy, dict_ax=dict_plot) aplot.uni_plot_ax_bis(0, self.xx, 3 * np.sin(self.xx) + 1, dict_ax=dict_plot2) self.image_name = "image_set_dict_ax_xscale_2_different_scales" self.check_plot() with self.subTest('yscale different'): aplot = APlot() dict_plot = {'yscale': 'log'} dict_plot2 = {'yscale': 'linear'} aplot.uni_plot(0, self.xx, yy, dict_ax=dict_plot) aplot.uni_plot_ax_bis(0, self.xx, 3 * np.sin(self.xx) + 1, dict_ax=dict_plot2) self.image_name = "image_set_dict_ax_yscale_2_different" self.check_plot() # with self.subTest('xint same'): # aplot = APlot() # # dict_plot = {'xint': True} # # aplot.uni_plot(0, self.xx, yy, dict_ax=dict_plot) # aplot.uni_plot_ax_bis(0, self.xx, 3 * np.sin(self.xx) + 1, dict_ax=dict_plot) # # plt.savefig("image_reference_test_plot/test_image_set_dict_ax_xint_2_same.png") # # with self.subTest('xint_yint same'): # aplot = APlot() # # dict_plot = {'xint': True, 'yint': True} # # aplot.uni_plot(0, self.xx, yy, dict_ax=dict_plot) # aplot.uni_plot_ax_bis(0, self.xx, 3 * np.sin(self.xx) + 1, dict_ax=dict_plot) # # plt.savefig("image_reference_test_plot/test_image_set_dict_ax_xyint_same_2.png") # with self.subTest('xint different'): # aplot = APlot() # # dict_plot = {'xint': True} # dict_plot2 = {'xint': False} # # aplot.uni_plot(0, self.xx, yy, dict_ax=dict_plot) # aplot.uni_plot_ax_bis(0, self.xx, 3 * np.sin(self.xx) + 1, dict_ax=dict_plot2) # # plt.savefig("image_reference_test_plot/test_image_set_dict_ax_xint_2_different_2.png") # # with self.subTest('xint_yint different'): # aplot = APlot() # # dict_plot = {'xint': True, 'yint': True} # dict_plot2 = {'xint': True, 'yint': False} # # aplot.uni_plot(0, self.xx, yy, dict_ax=dict_plot) # aplot.uni_plot_ax_bis(0, self.xx, 3 * np.sin(self.xx) + 1, dict_ax=dict_plot2) # # plt.savefig("image_reference_test_plot/test_image_set_dict_ax_xyint_different_2.png") with self.subTest('xlim'): aplot = APlot() dict_plot1 = {'xlim': [0, 0.5]} dict_plot2 = {'xlim': [0, 1.5]} aplot.uni_plot(0, self.xx, yy, dict_ax=dict_plot1) aplot.uni_plot_ax_bis(0, self.xx, 3 * np.sin(self.xx) + 1, dict_ax=dict_plot2) self.image_name = "image_set_dict_ax_xlim_2" self.check_plot() with self.subTest('ylim'): aplot = APlot() dict_plot1 = {'ylim': [1, 5]} dict_plot2 = {'ylim': [1, 15]} aplot.uni_plot(0, self.xx, yy, dict_ax=dict_plot1) aplot.uni_plot_ax_bis(0, self.xx, 3 * np.sin(self.xx) + 1, dict_ax=dict_plot2) self.image_name = "image_set_dict_ax_ylim_2" self.check_plot()