Browse Source

Some tweaking of axis limits

tforest 9 months ago
parent
commit
0ffb02e511
1 changed files with 24 additions and 5 deletions
  1. 24 5
      swp2.py

+ 24 - 5
swp2.py View File

@@ -483,8 +483,12 @@ def plot_scaled_theta(plot_lines, prop, title, mu, tgen, swp2_lines = None, ax =
483 483
         if subset is not None:
484 484
             if breaks in subset:
485 485
                 masking_alpha = 0.75
486
+                autoscale = True
486 487
             else:
487 488
                 masking_alpha = 0
489
+                autoscale = False
490
+        ax2.set_autoscale_on(autoscale)
491
+        ax3.set_autoscale_on(autoscale)
488 492
         p2, = ax2.plot(x2_plot, y2_plot, 'o', linestyle="-", alpha=masking_alpha, lw=2, label = str(breaks)+' brks')
489 493
         # Plotting (fig 3) which is the same but log scale for x
490 494
         p3, = ax3.plot(x2_plot, y2_plot, 'o', linestyle="-", alpha=masking_alpha, lw=2, label = str(breaks)+' brks')
@@ -497,16 +501,24 @@ def plot_scaled_theta(plot_lines, prop, title, mu, tgen, swp2_lines = None, ax =
497 501
         xlabel = "Theta scaled by N0"
498 502
         ylabel = "Theta scaled by N0"
499 503
     else:
500
-        xlabel = "t"
501
-        ylabel = r"$\theta$"
504
+        xlabel = "time"
505
+        ylabel = "Effective pop. size (Ne)"
502 506
     if ax is None:
503 507
         # if not ax, then use the plt syntax, not ax...
504 508
         plt.xlabel(xlabel, fontsize=fnt_size)
505 509
         plt.ylabel(ylabel, fontsize=fnt_size)
506 510
         plt.xlim(left=0)
511
+        xlim_val = plt.gca().get_xlim()
507 512
         x_ticks = list(plt.xticks())[0]
508 513
         plt.gca().set_xticks(x_ticks)
514
+        plt.gca().set_xlim(xlim_val)
509 515
         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)
516
+        # rescale y to effective pop size
517
+        ylim_val = plt.gca().get_ylim()
518
+        y_ticks = list(plt.yticks())[0]
519
+        plt.gca().set_yticks(y_ticks)
520
+        plt.gca().set_ylim(ylim_val)
521
+        plt.gca().set_yticklabels([f'{k/(4*mu):.0e}' for k in y_ticks], fontsize = fnt_size*0.5)
510 522
         plt.title(title, fontsize=fnt_size)
511 523
         plt.legend(handles=lines_fig2, loc='best', fontsize = fnt_size*0.5)
512 524
         plt.text(-0.13, -0.135, 'Coal. time\nGen. time\nYears', ha='left', va='bottom', transform=ax3.transAxes)
@@ -522,14 +534,21 @@ def plot_scaled_theta(plot_lines, prop, title, mu, tgen, swp2_lines = None, ax =
522 534
         ax2.legend(handles=lines_fig2, loc='best', fontsize = fnt_size*0.5)
523 535
     ax3.set_xscale('log')
524 536
     ax3.set_yscale('log')
525
-    ax3.set_xlabel("time log scale", fontsize=fnt_size)
526
-    ax3.set_ylabel("theta", fontsize=fnt_size)
537
+    ax3.set_xlabel(xlabel, fontsize=fnt_size)
538
+    ax3.set_ylabel(ylabel, fontsize=fnt_size)
527 539
     ax3.set_title(title, fontsize=fnt_size)
528 540
     ax3.legend(handles=lines_fig3, loc='best', fontsize = fnt_size*0.5)
541
+    xlim_val = ax3.get_xlim()
529 542
     x_ticks = list(ax3.get_xticks())
530
-    ax3.set_xlim(left=min(x_ticks))
531 543
     ax3.set_xticks(x_ticks)
544
+    ax3.set_xlim(xlim_val)
532 545
     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)
546
+    ylim_val = ax3.get_ylim()
547
+    # rescale y to effective pop size
548
+    y_ticks = list(ax3.get_yticks())
549
+    ax3.set_yticks(y_ticks)
550
+    ax3.set_ylim(ylim_val)
551
+    ax3.set_yticklabels([f'{k/(4*mu):.0e}' for k in y_ticks], fontsize = fnt_size*0.5)
533 552
     plt.text(-0.13, -0.135, 'Coal. time\nGen. time\nYears', ha='left', va='bottom', transform=ax3.transAxes)
534 553
     plt.subplots_adjust(bottom=0.2)  # Adjust the value as needed
535 554
     if ax is None: