Skip to content

Commit e3ed0f1

Browse files
committed
Rename some variables for clarity or pep8, and reorder arguments...
... in internal APIs to always have x/width first, y/height second.
1 parent c739a08 commit e3ed0f1

File tree

1 file changed

+35
-37
lines changed

1 file changed

+35
-37
lines changed

lib/mpl_toolkits/axes_grid1/axes_divider.py

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -584,48 +584,48 @@ def get_subplotspec(self):
584584

585585

586586
# Helper for HBoxDivider/VBoxDivider.
587-
def _determine_karray(equivalent_sizes, appended_sizes,
588-
max_equivalent_size, total_appended_size):
589-
n = len(equivalent_sizes)
590-
eq_rs, eq_as = np.asarray(equivalent_sizes).T
591-
ap_rs, ap_as = np.asarray(appended_sizes).T
587+
# The variable names are written for a horizontal layout, but the calculations
588+
# work identically for vertical layouts (and likewise for the helpers below).
589+
def _determine_karray(summed_widths, equal_heights, total_width, max_height):
590+
n = len(equal_heights)
591+
eq_rs, eq_as = np.asarray(equal_heights).T
592+
sm_rs, sm_as = np.asarray(summed_widths).T
592593
A = np.zeros((n + 1, n + 1))
593594
B = np.zeros(n + 1)
594595
np.fill_diagonal(A[:n, :n], eq_rs)
595596
A[:n, -1] = -1
596-
A[-1, :-1] = ap_rs
597+
A[-1, :-1] = sm_rs
597598
B[:n] = -eq_as
598-
B[-1] = total_appended_size - sum(ap_as)
599+
B[-1] = total_width - sum(sm_as)
599600
# A @ K = B: This solves for {k_0, ..., k_{N-1}, H} so that
600601
# eq_r_i * k_i + eq_a_i = H for all i: all axes have the same height
601-
# sum(ap_r_i * k_i + ap_a_i) = total_summed_width: fixed total width
602+
# sum(sm_r_i * k_i + sm_a_i) = total_summed_width: fixed total width
602603
# (foo_r_i * k_i + foo_a_i will end up being the size of foo.)
603-
karray_H = np.linalg.solve(A, B)
604-
karray = karray_H[:-1]
605-
H = karray_H[-1]
606-
if H > max_equivalent_size: # Additionally, upper-bound the height.
607-
karray = (max_equivalent_size - eq_as) / eq_rs
604+
karray_and_height = np.linalg.solve(A, B)
605+
karray = karray_and_height[:-1]
606+
height = karray_and_height[-1]
607+
if height > max_height: # Additionally, upper-bound the height.
608+
karray = (max_height - eq_as) / eq_rs
608609
return karray
609610

610611

611-
# Helper for HBoxDivider/VBoxDivider.
612-
def _calc_offsets(appended_sizes, karray):
612+
# Helper for HBoxDivider/VBoxDivider (see above re: variable naming).
613+
def _calc_offsets(summed_sizes, karray):
613614
offsets = [0.]
614-
for (r, a), k in zip(appended_sizes, karray):
615+
for (r, a), k in zip(summed_sizes, karray):
615616
offsets.append(offsets[-1] + r*k + a)
616617
return offsets
617618

618619

619-
# Helper for HBoxDivider/VBoxDivider.
620-
def _locate(
621-
x, y, w, h, equivalent_sizes, appended_sizes, fig_w, fig_h, anchor):
620+
# Helper for HBoxDivider/VBoxDivider (see above re: variable naming).
621+
def _locate(x, y, w, h, summed_widths, equal_heights, fig_w, fig_h, anchor):
622622
karray = _determine_karray(
623-
equivalent_sizes, appended_sizes,
624-
max_equivalent_size=fig_h * h, total_appended_size=fig_w * w)
625-
ox = _calc_offsets(appended_sizes, karray)
623+
summed_widths, equal_heights,
624+
total_width=fig_w * w, max_height=fig_h * h)
625+
ox = _calc_offsets(summed_widths, karray)
626626

627627
ww = (ox[-1] - ox[0]) / fig_w
628-
h0_r, h0_a = equivalent_sizes[0]
628+
h0_r, h0_a = equal_heights[0]
629629
hh = (karray[0]*h0_r + h0_a) / fig_h
630630
pb = mtransforms.Bbox.from_bounds(x, y, w, h)
631631
pb1 = mtransforms.Bbox.from_bounds(x, y, ww, hh)
@@ -661,16 +661,15 @@ def new_locator(self, nx, nx1=None):
661661

662662
def locate(self, nx, ny, nx1=None, ny1=None, axes=None, renderer=None):
663663
# docstring inherited
664-
figW, figH = self._fig.get_size_inches()
664+
fig_w, fig_h = self._fig.get_size_inches()
665665
x, y, w, h = self.get_position_runtime(axes, renderer)
666-
y_equivalent_sizes = self.get_vertical_sizes(renderer)
667-
x_appended_sizes = self.get_horizontal_sizes(renderer)
668-
x0, y0, ox, hh = _locate(x, y, w, h,
669-
y_equivalent_sizes, x_appended_sizes,
670-
figW, figH, self.get_anchor())
666+
summed_ws = self.get_horizontal_sizes(renderer)
667+
equal_hs = self.get_vertical_sizes(renderer)
668+
x0, y0, ox, hh = _locate(
669+
x, y, w, h, summed_ws, equal_hs, fig_w, fig_h, self.get_anchor())
671670
if nx1 is None:
672671
nx1 = nx + 1
673-
x1, w1 = x0 + ox[nx] / figW, (ox[nx1] - ox[nx]) / figW
672+
x1, w1 = x0 + ox[nx] / fig_w, (ox[nx1] - ox[nx]) / fig_w
674673
y1, h1 = y0, hh
675674
return mtransforms.Bbox.from_bounds(x1, y1, w1, h1)
676675

@@ -697,17 +696,16 @@ def new_locator(self, ny, ny1=None):
697696

698697
def locate(self, nx, ny, nx1=None, ny1=None, axes=None, renderer=None):
699698
# docstring inherited
700-
figW, figH = self._fig.get_size_inches()
699+
fig_w, fig_h = self._fig.get_size_inches()
701700
x, y, w, h = self.get_position_runtime(axes, renderer)
702-
x_equivalent_sizes = self.get_horizontal_sizes(renderer)
703-
y_appended_sizes = self.get_vertical_sizes(renderer)
704-
y0, x0, oy, ww = _locate(y, x, h, w,
705-
x_equivalent_sizes, y_appended_sizes,
706-
figH, figW, self.get_anchor())
701+
summed_hs = self.get_vertical_sizes(renderer)
702+
equal_ws = self.get_horizontal_sizes(renderer)
703+
y0, x0, oy, ww = _locate(
704+
y, x, h, w, summed_hs, equal_ws, fig_h, fig_w, self.get_anchor())
707705
if ny1 is None:
708706
ny1 = ny + 1
709707
x1, w1 = x0, ww
710-
y1, h1 = y0 + oy[ny] / figH, (oy[ny1] - oy[ny]) / figH
708+
y1, h1 = y0 + oy[ny] / fig_h, (oy[ny1] - oy[ny]) / fig_h
711709
return mtransforms.Bbox.from_bounds(x1, y1, w1, h1)
712710

713711

0 commit comments

Comments
 (0)