Browse Source

Adjust xlim and ylims for swp2

tforest 10 months ago
parent
commit
7949befb40
1 changed files with 18 additions and 5 deletions
  1. 18 5
      swp2.py

+ 18 - 5
swp2.py View File

@@ -480,7 +480,8 @@ def plot_scaled_theta(plot_lines, prop, title, mu, tgen, swp2_lines = None, ax =
480 480
             swp2_lines[0][k] = swp2_lines[0][k]/tgen*mu
481 481
         for k in range(len(swp2_lines[1])):
482 482
             swp2_lines[1][k] = swp2_lines[1][k]*4*mu
483
-        x2_plot, y2_plot = plot_straight_x_y(swp2_lines[0],swp2_lines[1])
483
+        # x2_plot, y2_plot = plot_straight_x_y(swp2_lines[0],swp2_lines[1])
484
+        x2_plot, y2_plot = swp2_lines[0], swp2_lines[1]
484 485
         p2, = ax2.plot(x2_plot, y2_plot, linestyle="-", alpha=0.75, lw=2, label = 'swp2', color="black")
485 486
         lines_fig2.append(p2)
486 487
         # 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 =
530 531
         # plt.gca().set_xticks(x_ticks)
531 532
         plt.xticks(x_ticks)
532 533
         # plt.gca().set_xlim(xlim_val)
533
-        plt.xlim(min_x, max_x)
534
+        plt.xlim(min(min_x,min(swp2_lines[0])), max(max(swp2_lines[0]), max_x))
534 535
         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)
535 536
         # rescale y to effective pop size
536 537
         # ylim_val = plt.gca().get_ylim()
@@ -538,7 +539,7 @@ def plot_scaled_theta(plot_lines, prop, title, mu, tgen, swp2_lines = None, ax =
538 539
         # plt.gca().set_yticks(y_ticks)
539 540
         # plt.gca().set_ylim(ylim_val)
540 541
         plt.yticks(y_ticks)
541
-        plt.ylim(min_y, max_y+(max_y*0.05))
542
+        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)))
542 543
         plt.gca().set_yticklabels([f'{k/(4*mu):.0e}' for k in y_ticks], fontsize = fnt_size*0.5)
543 544
         plt.title(title, fontsize=fnt_size)
544 545
         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 =
562 563
     # Scale the x-axis
563 564
     x_ticks = list(ax3.get_xticks())
564 565
     ax3.set_xticks(x_ticks)
565
-    ax3.set_xlim(min(x_ticks), max_x)
566
+    ax3.set_xlim(min(min(x_ticks), min(swp2_lines[0])), max(max_x, max(swp2_lines[0])))
566 567
     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)
567 568
     # rescale y to effective pop size
568 569
     y_ticks = list(ax3.get_yticks())
569 570
     ax3.set_yticks(y_ticks)
570
-    ax3.set_ylim(min(y_ticks), max_y+(max_y*0.5))
571
+    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)))
571 572
     ax3.set_yticklabels([f'{k/(4*mu):.0e}' for k in y_ticks], fontsize = fnt_size*0.5)
572 573
     plt.text(-0.13, -0.135, 'Coal. time\nGen. time\nYears', ha='left', va='bottom', transform=ax3.transAxes)
573 574
     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 =
674 675
     swp2_summary = "/".join(folder_splitted[:-2])+'/'+folder_splitted[-3]+".final.summary"
675 676
     swp2_vals = parse_stairwayplot_output_summary(stwplt_out = swp2_summary)
676 677
     swp2_x, swp2_y = swp2_vals[0], swp2_vals[1]
678
+    remove_back_and_forth_points(swp2_x, swp2_y) 
677 679
     # End of Parsing real swp2 output
678 680
     plot_raw_stairs(plot_lines = loaded_data['raw_stairs'],
679 681
                             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 =
684 686
 
685 687
     # plt.close(fig1)
686 688
     # plt.close(fig2)
689
+
690
+def remove_back_and_forth_points(x_values, y_values):
691
+    # to deal with some weirdness of plotting that occur sometimes with the swp2 output
692
+    # sometimes the line is going back and forth as x_k > x_(k+1), which is normally not possible
693
+    i = 0
694
+    while i < len(x_values) - 1:
695
+        if x_values[i] >= x_values[i+1]:
696
+            del x_values[i]
697
+            del y_values[i]
698
+        else:
699
+            i += 1
687 700
 def parse_stairwayplot_output_summary(stwplt_out, xlim = None, ylim = None, title = "default title", plot = False):
688 701
     #col 5
689 702
     year = []