Adjust xlim and ylims for swp2
parent
658693c2a2
commit
7949befb40
23
swp2.py
23
swp2.py
|
|
@ -480,7 +480,8 @@ def plot_scaled_theta(plot_lines, prop, title, mu, tgen, swp2_lines = None, ax =
|
|||
swp2_lines[0][k] = swp2_lines[0][k]/tgen*mu
|
||||
for k in range(len(swp2_lines[1])):
|
||||
swp2_lines[1][k] = swp2_lines[1][k]*4*mu
|
||||
x2_plot, y2_plot = plot_straight_x_y(swp2_lines[0],swp2_lines[1])
|
||||
# x2_plot, y2_plot = plot_straight_x_y(swp2_lines[0],swp2_lines[1])
|
||||
x2_plot, y2_plot = swp2_lines[0], swp2_lines[1]
|
||||
p2, = ax2.plot(x2_plot, y2_plot, linestyle="-", alpha=0.75, lw=2, label = 'swp2', color="black")
|
||||
lines_fig2.append(p2)
|
||||
# Plotting (fig 3) which is the same but log scale for x
|
||||
|
|
@ -530,7 +531,7 @@ def plot_scaled_theta(plot_lines, prop, title, mu, tgen, swp2_lines = None, ax =
|
|||
# plt.gca().set_xticks(x_ticks)
|
||||
plt.xticks(x_ticks)
|
||||
# plt.gca().set_xlim(xlim_val)
|
||||
plt.xlim(min_x, max_x)
|
||||
plt.xlim(min(min_x,min(swp2_lines[0])), max(max(swp2_lines[0]), 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()
|
||||
|
|
@ -538,7 +539,7 @@ def plot_scaled_theta(plot_lines, prop, title, mu, tgen, swp2_lines = None, ax =
|
|||
# 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.ylim(min(min_y,min(swp2_lines[1])), max(max_y+(max_y*0.05), max(swp2_lines[1])+(max(swp2_lines[1])*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)
|
||||
|
|
@ -562,12 +563,12 @@ def plot_scaled_theta(plot_lines, prop, title, mu, tgen, swp2_lines = None, ax =
|
|||
# Scale the x-axis
|
||||
x_ticks = list(ax3.get_xticks())
|
||||
ax3.set_xticks(x_ticks)
|
||||
ax3.set_xlim(min(x_ticks), max_x)
|
||||
ax3.set_xlim(min(min(x_ticks), min(swp2_lines[0])), max(max_x, max(swp2_lines[0])))
|
||||
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)
|
||||
# rescale y to effective pop size
|
||||
y_ticks = list(ax3.get_yticks())
|
||||
ax3.set_yticks(y_ticks)
|
||||
ax3.set_ylim(min(y_ticks), max_y+(max_y*0.5))
|
||||
ax3.set_ylim(min(min(y_ticks), min(swp2_lines[1])), max(max_y+(max_y*0.5), max(swp2_lines[1])+(max(swp2_lines[1])*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
|
||||
|
|
@ -674,6 +675,7 @@ def combined_plot(folder_path, mu, tgen, breaks, title = "Title", theta_scale =
|
|||
swp2_summary = "/".join(folder_splitted[:-2])+'/'+folder_splitted[-3]+".final.summary"
|
||||
swp2_vals = parse_stairwayplot_output_summary(stwplt_out = swp2_summary)
|
||||
swp2_x, swp2_y = swp2_vals[0], swp2_vals[1]
|
||||
remove_back_and_forth_points(swp2_x, swp2_y)
|
||||
# End of Parsing real swp2 output
|
||||
plot_raw_stairs(plot_lines = loaded_data['raw_stairs'],
|
||||
prop = loaded_data['prop'], title = title, ax = None, max_breaks = breaks)
|
||||
|
|
@ -684,6 +686,17 @@ def combined_plot(folder_path, mu, tgen, breaks, title = "Title", theta_scale =
|
|||
|
||||
# plt.close(fig1)
|
||||
# plt.close(fig2)
|
||||
|
||||
def remove_back_and_forth_points(x_values, y_values):
|
||||
# to deal with some weirdness of plotting that occur sometimes with the swp2 output
|
||||
# sometimes the line is going back and forth as x_k > x_(k+1), which is normally not possible
|
||||
i = 0
|
||||
while i < len(x_values) - 1:
|
||||
if x_values[i] >= x_values[i+1]:
|
||||
del x_values[i]
|
||||
del y_values[i]
|
||||
else:
|
||||
i += 1
|
||||
def parse_stairwayplot_output_summary(stwplt_out, xlim = None, ylim = None, title = "default title", plot = False):
|
||||
#col 5
|
||||
year = []
|
||||
|
|
|
|||
Loading…
Reference in New Issue