Browse Source

Fixing some plotting issues for swp2

tforest 2 months ago
parent
commit
658693c2a2
1 changed files with 24 additions and 13 deletions
  1. 24 13
      swp2.py

+ 24 - 13
swp2.py View File

@@ -486,6 +486,10 @@ def plot_scaled_theta(plot_lines, prop, title, mu, tgen, swp2_lines = None, ax =
486 486
         # Plotting (fig 3) which is the same but log scale for x
487 487
         p3, = ax3.plot(x2_plot, y2_plot, linestyle="-", alpha=0.75, lw=2, label = 'swp2', color="black")
488 488
         lines_fig3.append(p3)
489
+    min_x = 0
490
+    min_y = 0
491
+    max_x = 0
492
+    max_y = 0
489 493
     for breaks, plot in enumerate(plot_lines):
490 494
         x,y=plot
491 495
         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 =
493 497
             if breaks in subset:
494 498
                 masking_alpha = 0.75
495 499
                 autoscale = True
500
+                min_x = min(min_x, min(x2_plot))
501
+                min_y = min(min_y, min(y2_plot))
502
+                max_x = max(max_x, max(x2_plot))
503
+                max_y = max(max_y, max(y2_plot))
496 504
             else:
497 505
                 masking_alpha = 0
498 506
                 autoscale = False
@@ -516,17 +524,21 @@ def plot_scaled_theta(plot_lines, prop, title, mu, tgen, swp2_lines = None, ax =
516 524
         # if not ax, then use the plt syntax, not ax...
517 525
         plt.xlabel(xlabel, fontsize=fnt_size)
518 526
         plt.ylabel(ylabel, fontsize=fnt_size)
519
-        plt.xlim(left=0)
520
-        xlim_val = plt.gca().get_xlim()
527
+        #plt.xlim(left=0)
528
+        #xlim_val = plt.gca().get_xlim()
521 529
         x_ticks = list(plt.xticks())[0]
522
-        plt.gca().set_xticks(x_ticks)
523
-        plt.gca().set_xlim(xlim_val)
530
+        # plt.gca().set_xticks(x_ticks)
531
+        plt.xticks(x_ticks)
532
+        # plt.gca().set_xlim(xlim_val)
533
+        plt.xlim(min_x, max_x)
524 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)
525 535
         # rescale y to effective pop size
526
-        ylim_val = plt.gca().get_ylim()
536
+        # ylim_val = plt.gca().get_ylim()
527 537
         y_ticks = list(plt.yticks())[0]
528
-        plt.gca().set_yticks(y_ticks)
529
-        plt.gca().set_ylim(ylim_val)
538
+        # plt.gca().set_yticks(y_ticks)
539
+        # plt.gca().set_ylim(ylim_val)
540
+        plt.yticks(y_ticks)
541
+        plt.ylim(min_y, max_y+(max_y*0.05))
530 542
         plt.gca().set_yticklabels([f'{k/(4*mu):.0e}' for k in y_ticks], fontsize = fnt_size*0.5)
531 543
         plt.title(title, fontsize=fnt_size)
532 544
         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 =
541 553
         ax2.set_ylabel(ylabel, fontsize=fnt_size)
542 554
         ax2.set_title(title, fontsize=fnt_size)
543 555
         ax2.legend(handles=lines_fig2, loc='best', fontsize = fnt_size*0.5)
544
-    ax3.set_xscale('log')
545
-    ax3.set_yscale('log')
546 556
     ax3.set_xlabel(xlabel, fontsize=fnt_size)
547 557
     ax3.set_ylabel(ylabel, fontsize=fnt_size)
548 558
     ax3.set_title(title, fontsize=fnt_size)
549 559
     ax3.legend(handles=lines_fig3, loc='best', fontsize = fnt_size*0.5)
550
-    xlim_val = ax3.get_xlim()
560
+    ax3.set_xscale('log')
561
+    ax3.set_yscale('log')
562
+    # Scale the x-axis
551 563
     x_ticks = list(ax3.get_xticks())
552 564
     ax3.set_xticks(x_ticks)
553
-    ax3.set_xlim(xlim_val)
565
+    ax3.set_xlim(min(x_ticks), max_x)
554 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)
555
-    ylim_val = ax3.get_ylim()
556 567
     # rescale y to effective pop size
557 568
     y_ticks = list(ax3.get_yticks())
558 569
     ax3.set_yticks(y_ticks)
559
-    ax3.set_ylim(ylim_val)
570
+    ax3.set_ylim(min(y_ticks), max_y+(max_y*0.5))
560 571
     ax3.set_yticklabels([f'{k/(4*mu):.0e}' for k in y_ticks], fontsize = fnt_size*0.5)
561 572
     plt.text(-0.13, -0.135, 'Coal. time\nGen. time\nYears', ha='left', va='bottom', transform=ax3.transAxes)
562 573
     plt.subplots_adjust(bottom=0.2)  # Adjust the value as needed