Browse Source

Adjust xlim and ylims for swp2

tforest 9 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
             swp2_lines[0][k] = swp2_lines[0][k]/tgen*mu
480
             swp2_lines[0][k] = swp2_lines[0][k]/tgen*mu
481
         for k in range(len(swp2_lines[1])):
481
         for k in range(len(swp2_lines[1])):
482
             swp2_lines[1][k] = swp2_lines[1][k]*4*mu
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
         p2, = ax2.plot(x2_plot, y2_plot, linestyle="-", alpha=0.75, lw=2, label = 'swp2', color="black")
485
         p2, = ax2.plot(x2_plot, y2_plot, linestyle="-", alpha=0.75, lw=2, label = 'swp2', color="black")
485
         lines_fig2.append(p2)
486
         lines_fig2.append(p2)
486
         # Plotting (fig 3) which is the same but log scale for x
487
         # Plotting (fig 3) which is the same but log scale for x
530
         # plt.gca().set_xticks(x_ticks)
531
         # plt.gca().set_xticks(x_ticks)
531
         plt.xticks(x_ticks)
532
         plt.xticks(x_ticks)
532
         # plt.gca().set_xlim(xlim_val)
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
         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
         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
         # rescale y to effective pop size
536
         # rescale y to effective pop size
536
         # ylim_val = plt.gca().get_ylim()
537
         # ylim_val = plt.gca().get_ylim()
538
         # plt.gca().set_yticks(y_ticks)
539
         # plt.gca().set_yticks(y_ticks)
539
         # plt.gca().set_ylim(ylim_val)
540
         # plt.gca().set_ylim(ylim_val)
540
         plt.yticks(y_ticks)
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
         plt.gca().set_yticklabels([f'{k/(4*mu):.0e}' for k in y_ticks], fontsize = fnt_size*0.5)
543
         plt.gca().set_yticklabels([f'{k/(4*mu):.0e}' for k in y_ticks], fontsize = fnt_size*0.5)
543
         plt.title(title, fontsize=fnt_size)
544
         plt.title(title, fontsize=fnt_size)
544
         plt.legend(handles=lines_fig2, loc='best', fontsize = fnt_size*0.5)
545
         plt.legend(handles=lines_fig2, loc='best', fontsize = fnt_size*0.5)
562
     # Scale the x-axis
563
     # Scale the x-axis
563
     x_ticks = list(ax3.get_xticks())
564
     x_ticks = list(ax3.get_xticks())
564
     ax3.set_xticks(x_ticks)
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
     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
     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
     # rescale y to effective pop size
568
     # rescale y to effective pop size
568
     y_ticks = list(ax3.get_yticks())
569
     y_ticks = list(ax3.get_yticks())
569
     ax3.set_yticks(y_ticks)
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
     ax3.set_yticklabels([f'{k/(4*mu):.0e}' for k in y_ticks], fontsize = fnt_size*0.5)
572
     ax3.set_yticklabels([f'{k/(4*mu):.0e}' for k in y_ticks], fontsize = fnt_size*0.5)
572
     plt.text(-0.13, -0.135, 'Coal. time\nGen. time\nYears', ha='left', va='bottom', transform=ax3.transAxes)
573
     plt.text(-0.13, -0.135, 'Coal. time\nGen. time\nYears', ha='left', va='bottom', transform=ax3.transAxes)
573
     plt.subplots_adjust(bottom=0.2)  # Adjust the value as needed
574
     plt.subplots_adjust(bottom=0.2)  # Adjust the value as needed
674
     swp2_summary = "/".join(folder_splitted[:-2])+'/'+folder_splitted[-3]+".final.summary"
675
     swp2_summary = "/".join(folder_splitted[:-2])+'/'+folder_splitted[-3]+".final.summary"
675
     swp2_vals = parse_stairwayplot_output_summary(stwplt_out = swp2_summary)
676
     swp2_vals = parse_stairwayplot_output_summary(stwplt_out = swp2_summary)
676
     swp2_x, swp2_y = swp2_vals[0], swp2_vals[1]
677
     swp2_x, swp2_y = swp2_vals[0], swp2_vals[1]
678
+    remove_back_and_forth_points(swp2_x, swp2_y) 
677
     # End of Parsing real swp2 output
679
     # End of Parsing real swp2 output
678
     plot_raw_stairs(plot_lines = loaded_data['raw_stairs'],
680
     plot_raw_stairs(plot_lines = loaded_data['raw_stairs'],
679
                             prop = loaded_data['prop'], title = title, ax = None, max_breaks = breaks)
681
                             prop = loaded_data['prop'], title = title, ax = None, max_breaks = breaks)
684
 
686
 
685
     # plt.close(fig1)
687
     # plt.close(fig1)
686
     # plt.close(fig2)
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
 def parse_stairwayplot_output_summary(stwplt_out, xlim = None, ylim = None, title = "default title", plot = False):
700
 def parse_stairwayplot_output_summary(stwplt_out, xlim = None, ylim = None, title = "default title", plot = False):
688
     #col 5
701
     #col 5
689
     year = []
702
     year = []