From 658693c2a24767645329c43139e778b215d978be Mon Sep 17 00:00:00 2001 From: tforest Date: Sun, 25 Feb 2024 17:47:44 +0100 Subject: [PATCH] Fixing some plotting issues for swp2 --- swp2.py | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/swp2.py b/swp2.py index 69e6a24..ffbb2ae 100644 --- a/swp2.py +++ b/swp2.py @@ -486,6 +486,10 @@ def plot_scaled_theta(plot_lines, prop, title, mu, tgen, swp2_lines = None, ax = # Plotting (fig 3) which is the same but log scale for x p3, = ax3.plot(x2_plot, y2_plot, linestyle="-", alpha=0.75, lw=2, label = 'swp2', color="black") lines_fig3.append(p3) + min_x = 0 + min_y = 0 + max_x = 0 + max_y = 0 for breaks, plot in enumerate(plot_lines): x,y=plot x2_plot, y2_plot = plot_straight_x_y(x,y) @@ -493,6 +497,10 @@ def plot_scaled_theta(plot_lines, prop, title, mu, tgen, swp2_lines = None, ax = if breaks in subset: masking_alpha = 0.75 autoscale = True + min_x = min(min_x, min(x2_plot)) + min_y = min(min_y, min(y2_plot)) + max_x = max(max_x, max(x2_plot)) + max_y = max(max_y, max(y2_plot)) else: masking_alpha = 0 autoscale = False @@ -516,17 +524,21 @@ def plot_scaled_theta(plot_lines, prop, title, mu, tgen, swp2_lines = None, ax = # if not ax, then use the plt syntax, not ax... plt.xlabel(xlabel, fontsize=fnt_size) plt.ylabel(ylabel, fontsize=fnt_size) - plt.xlim(left=0) - xlim_val = plt.gca().get_xlim() + #plt.xlim(left=0) + #xlim_val = plt.gca().get_xlim() x_ticks = list(plt.xticks())[0] - plt.gca().set_xticks(x_ticks) - plt.gca().set_xlim(xlim_val) + # plt.gca().set_xticks(x_ticks) + plt.xticks(x_ticks) + # plt.gca().set_xlim(xlim_val) + plt.xlim(min_x, max_x) plt.gca().set_xticklabels([f'{k:.0e}\n{k/(mu):.0e}\n{k/(mu)*tgen:.0e}' for k in x_ticks], fontsize = fnt_size*0.5) # rescale y to effective pop size - ylim_val = plt.gca().get_ylim() + # ylim_val = plt.gca().get_ylim() y_ticks = list(plt.yticks())[0] - plt.gca().set_yticks(y_ticks) - plt.gca().set_ylim(ylim_val) + # plt.gca().set_yticks(y_ticks) + # plt.gca().set_ylim(ylim_val) + plt.yticks(y_ticks) + plt.ylim(min_y, max_y+(max_y*0.05)) plt.gca().set_yticklabels([f'{k/(4*mu):.0e}' for k in y_ticks], fontsize = fnt_size*0.5) plt.title(title, fontsize=fnt_size) plt.legend(handles=lines_fig2, loc='best', fontsize = fnt_size*0.5) @@ -541,22 +553,21 @@ def plot_scaled_theta(plot_lines, prop, title, mu, tgen, swp2_lines = None, ax = ax2.set_ylabel(ylabel, fontsize=fnt_size) ax2.set_title(title, fontsize=fnt_size) ax2.legend(handles=lines_fig2, loc='best', fontsize = fnt_size*0.5) - ax3.set_xscale('log') - ax3.set_yscale('log') ax3.set_xlabel(xlabel, fontsize=fnt_size) ax3.set_ylabel(ylabel, fontsize=fnt_size) ax3.set_title(title, fontsize=fnt_size) ax3.legend(handles=lines_fig3, loc='best', fontsize = fnt_size*0.5) - xlim_val = ax3.get_xlim() + ax3.set_xscale('log') + ax3.set_yscale('log') + # Scale the x-axis x_ticks = list(ax3.get_xticks()) ax3.set_xticks(x_ticks) - ax3.set_xlim(xlim_val) + ax3.set_xlim(min(x_ticks), max_x) ax3.set_xticklabels([f'{k:.0e}\n{k/(mu):.0e}\n{k/(mu)*tgen:.0e}' for k in x_ticks], fontsize = fnt_size*0.5) - ylim_val = ax3.get_ylim() # rescale y to effective pop size y_ticks = list(ax3.get_yticks()) ax3.set_yticks(y_ticks) - ax3.set_ylim(ylim_val) + ax3.set_ylim(min(y_ticks), max_y+(max_y*0.5)) ax3.set_yticklabels([f'{k/(4*mu):.0e}' for k in y_ticks], fontsize = fnt_size*0.5) plt.text(-0.13, -0.135, 'Coal. time\nGen. time\nYears', ha='left', va='bottom', transform=ax3.transAxes) plt.subplots_adjust(bottom=0.2) # Adjust the value as needed