Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 132e42d

Browse files
committed
ENH: Subpanels
1 parent 682836c commit 132e42d

File tree

4 files changed

+1809
-1564
lines changed

4 files changed

+1809
-1564
lines changed

lib/matplotlib/_constrained_layout.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def _make_layout_margins(fig, renderer, *, w_pad=0, h_pad=0,
208208
panel._layoutgrid.parent.edit_outer_margin_mins(margins, ss)
209209

210210
# for ax in [a for a in fig._localaxes if hasattr(a, 'get_subplotspec')]:
211-
for ax in fig.get_axes():
211+
for ax in fig._localaxes:
212212
if not hasattr(ax, 'get_subplotspec'):
213213
continue
214214

@@ -223,7 +223,6 @@ def _make_layout_margins(fig, renderer, *, w_pad=0, h_pad=0,
223223
hspace=hspace, wspace=wspace)
224224
margin0 = margin.copy()
225225
pos, bbox = _get_pos_and_bbox(ax, renderer)
226-
227226
# the margin is the distance between the bounding box of the axes
228227
# and its position (plus the padding from above)
229228
margin['left'] += pos.x0 - bbox.x0
@@ -456,7 +455,7 @@ def _reposition_axes(fig, renderer, *, w_pad=0, h_pad=0, hspace=0, wspace=0):
456455

457456
# for ax in fig._localaxes:
458457
# if not hasattr(a, 'get_subplotspec'):
459-
for ax in fig.get_axes():
458+
for ax in fig._localaxes:
460459
if not hasattr(ax, 'get_subplotspec'):
461460
continue
462461

lib/matplotlib/axes/_axes.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ def __init__(self, bounds, transform):
5555
self._transform = transform
5656

5757
def __call__(self, ax, renderer):
58-
# Subtracting transFigure will typically rely on inverted(), freezing
58+
# Subtracting transPanel will typically rely on inverted(), freezing
5959
# the transform; thus, this needs to be delayed until draw time as
60-
# transFigure may otherwise change after this is evaluated.
60+
# transPanel may otherwise change after this is evaluated.
6161
return mtransforms.TransformedBbox(
6262
mtransforms.Bbox.from_bounds(*self._bounds),
63-
self._transform - ax.figure.transFigure)
63+
self._transform - ax.figure.transPanel)
6464

6565

6666
# The axes module contains all the wrappers to plotting functions.
@@ -579,7 +579,7 @@ def indicate_inset(self, bounds, inset_ax=None, *, transform=None,
579579

580580
# decide which two of the lines to keep visible....
581581
pos = inset_ax.get_position()
582-
bboxins = pos.transformed(self.figure.transFigure)
582+
bboxins = pos.transformed(self.figure.transPanel)
583583
rectbbox = mtransforms.Bbox.from_bounds(
584584
*bounds
585585
).transformed(transform)

lib/matplotlib/axes/_base.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ def set_figure(self, fig):
629629
super().set_figure(fig)
630630

631631
self.bbox = mtransforms.TransformedBbox(self._position,
632-
fig.transFigure)
632+
fig.transPanel)
633633
# these will be updated later as data is added
634634
self.dataLim = mtransforms.Bbox.null()
635635
self._viewLim = mtransforms.Bbox.unit()
@@ -1607,9 +1607,11 @@ def apply_aspect(self, position=None):
16071607
self._set_position(position, which='active')
16081608
return
16091609

1610-
fig_width, fig_height = self.get_figure().get_size_inches()
1611-
fig_aspect = fig_height / fig_width
1612-
1610+
trans = self.get_figure().transPanel
1611+
bb = mtransforms.Bbox.from_bounds(0, 0, 1, 1).transformed(trans)
1612+
# this is the physical aspect of the panel (or figure):
1613+
fig_aspect = bb.height / bb.width
1614+
16131615
if self._adjustable == 'box':
16141616
if self in self._twinned_axes:
16151617
raise RuntimeError("Adjustable 'box' is not allowed in a "

0 commit comments

Comments
 (0)