@@ -151,6 +151,7 @@ def __init__(self,
151
151
self .clf ()
152
152
153
153
self ._cachedRenderer = None
154
+ self ._autoLayout = False
154
155
155
156
def _get_dpi (self ):
156
157
return self ._dpi
@@ -159,6 +160,9 @@ def _set_dpi(self, dpi):
159
160
self ._dpi_scale_trans .clear ().scale (dpi , dpi )
160
161
dpi = property (_get_dpi , _set_dpi )
161
162
163
+ def enable_auto_layout (self , setting = True ):
164
+ self ._autoLayout = setting
165
+
162
166
def autofmt_xdate (self , bottom = 0.2 , rotation = 30 , ha = 'right' ):
163
167
"""
164
168
A common use case is a number of subplots with shared xaxes
@@ -628,8 +632,9 @@ def draw(self, renderer):
628
632
# based on the tick and axis labels etc., and then makes sure
629
633
# that any axes that began life aligned to another axes remains
630
634
# aligned after these adjustments
631
- if len (self .axes ) > 1 :
635
+ if self . _autoLayout and len (self .axes ) > 1 :
632
636
aligned_positions = [{}, {}, {}, {}]
637
+ sizes = [{}, {}]
633
638
for a in self .axes :
634
639
a .update_layout (renderer )
635
640
orig_pos = a .get_position (True )
@@ -642,6 +647,15 @@ def draw(self, renderer):
642
647
pos [orig ][1 ].add (curr )
643
648
else :
644
649
pos [orig ] = [[a ], set ([curr ])]
650
+ for size , orig , curr in zip (sizes ,
651
+ orig_pos .size ,
652
+ curr_pos .size ):
653
+ orig = round (orig * 100.0 ) / 100.0
654
+ if orig in size :
655
+ size [orig ][0 ].append (a )
656
+ size [orig ][1 ].add (curr )
657
+ else :
658
+ size [orig ] = [[a ], set ([curr ])]
645
659
646
660
for i , pos in enumerate (aligned_positions ):
647
661
for axes , places in pos .values ():
@@ -654,7 +668,19 @@ def draw(self, renderer):
654
668
curr_pos = a .get_position ().frozen ()
655
669
curr_pos .get_points ()[i / 2 , i % 2 ] = curr
656
670
a .set_position (curr_pos , 'active' )
657
- else :
671
+
672
+ for i , size in enumerate (sizes ):
673
+ for axes , dims in size .values ():
674
+ new = min (dims )
675
+ for a in axes :
676
+ curr_pos = a .get_position ().frozen ()
677
+ curr = curr_pos .size [i ]
678
+ if curr > new :
679
+ extra = (curr - new ) * 0.5
680
+ curr_pos .get_points ()[0 , i ] += extra
681
+ curr_pos .get_points ()[1 , i ] -= extra
682
+ a .set_position (curr_pos , 'active' )
683
+ elif self ._autoLayout :
658
684
for a in self .axes : a .update_layout (renderer )
659
685
660
686
# render the axes
0 commit comments