8000 Make new auto-layout stuff optional (so it can be experimented on · heeres/matplotlib@6054f22 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6054f22

Browse files
committed
Make new auto-layout stuff optional (so it can be experimented on
without breaking too much.) svn path=/branches/transforms/; revision=4615
1 parent 124fe95 commit 6054f22

File tree

3 files changed

+31
-8
lines changed

3 files changed

+31
-8
lines changed

examples/simple_plot.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313
ylabel('voltage (mV)')
1414
title('About as simple as it gets, folks')
1515
grid(True)
16-
axes().xaxis.set_label_position('top')
17-
axes().xaxis.set_ticks_position('top')
18-
axes().yaxis.set_label_position('right')
1916

2017
#savefig('simple_plot.png')
2118
savefig('simple_plot')

lib/matplotlib/figure.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ def __init__(self,
151151
self.clf()
152152

153153
self._cachedRenderer = None
154+
self._autoLayout = False
154155

155156
def _get_dpi(self):
156157
return self._dpi
@@ -159,6 +160,9 @@ def _set_dpi(self, dpi):
159160
self._dpi_scale_trans.clear().scale(dpi, dpi)
160161
dpi = property(_get_dpi, _set_dpi)
161162

163+
def enable_auto_layout(self, setting=True):
164+
self._autoLayout = setting
165+
162166
def autofmt_xdate(self, bottom=0.2, rotation=30, ha='right'):
163167
"""
164168
A common use case is a number of subplots with shared xaxes
@@ -628,8 +632,9 @@ def draw(self, renderer):
628632
# based on the tick and axis labels etc., and then makes sure
629633
# that any axes that began life aligned to another axes remains
630634
# aligned after these adjustments
631-
if len(self.axes) > 1:
635+
if self._autoLayout and len(self.axes) > 1:
632636
aligned_positions = [{}, {}, {}, {}]
637+
sizes = [{}, {}]
633638
for a in self.axes:
634639
a.update_layout(renderer)
635640
orig_pos = a.get_position(True)
@@ -642,6 +647,15 @@ def draw(self, renderer):
642647
pos[orig][1].add(curr)
643648
else:
644649
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])]
645659

646660
for i, pos in enumerate(aligned_positions):
647661
for axes, places in pos.values():
@@ -654,7 +668,19 @@ def draw(self, renderer):
654668
curr_pos = a.get_position().frozen()
655669
curr_pos.get_points()[i/2, i%2] = curr
656670
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:
658684
for a in self.axes: a.update_layout(renderer)
659685

660686
# render the axes

lib/matplotlib/rcsetup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -440,12 +440,12 @@ def __call__(self, s):
440440
'figure.facecolor' : [ '0.75', validate_color], # facecolor; scalar gray
441441
'figure.edgecolor' : [ 'w', validate_color], # edgecolor; white
442442

443-
'figure.subplot.left' : [0.1, ValidateInterval(0, 1, closedmin=False, closedmax=False)],
443+
'figure.subplot.left' : [0.125, ValidateInterval(0, 1, closedmin=False, closedmax=False)],
444444
'figure.subplot.right' : [0.9, ValidateInterval(0, 1, closedmin=False, closedmax=False)],
445445
'figure.subplot.bottom' : [0.1, ValidateInterval(0, 1, closedmin=False, closedmax=False)],
446446
'figure.subplot.top' : [0.9, ValidateInterval(0, 1, closedmin=False, closedmax=False)],
447-
'figure.subplot.wspace' : [0.1, ValidateInterval(0, 1, closedmin=False, closedmax=True)],
448-
'figure.subplot.hspace' : [0.1, ValidateInterval(0, 1, closedmin=False, closedmax=True)],
447+
'figure.subplot.wspace' : [0.2, ValidateInterval(0, 1, closedmin=False, closedmax=True)],
448+
'figure.subplot.hspace' : [0.2, ValidateInterval(0, 1, closedmin=False, closedmax=True)],
449449

450450

451451
'savefig.dpi' : [100, validate_float], # DPI

0 commit comments

Comments
 (0)
0