Browse Source

Fixing some plotting issues for swp2

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