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

Skip to content

Simplify axes_pad handling in axes_grid. #15651

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 10, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 12 additions & 27 deletions lib/mpl_toolkits/axes_grid1/axes_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@
from .mpl_axes import Axes


def _extend_axes_pad(value):
# Check whether a list/tuple/array or scalar has been passed
ret = value
if not hasattr(ret, "__getitem__"):
ret = (value, value)
return ret


def _tick_only(ax, bottom_on, left_on):
bottom_off = not bottom_on
left_off = not left_on
Expand Down Expand Up @@ -143,8 +135,7 @@ def __init__(self, fig,
- "1": Only the bottom left axes is labelled.
- "all": all axes are labelled.

axes_class : a type that is a subclass of `matplotlib.axes.Axes`, \
default: None
axes_class : subclass of `matplotlib.axes.Axes`, default: None
"""
self._nrows, self._ncols = nrows_ncols

Expand Down Expand Up @@ -200,9 +191,7 @@ def __init__(self, fig,
self.set_label_mode(label_mode)

def _init_axes_pad(self, axes_pad):
axes_pad = _extend_axes_pad(axes_pad)
self._axes_pad = axes_pad

axes_pad = np.broadcast_to(axes_pad, 2)
self._horiz_pad_size = Size.Fixed(axes_pad[0])
self._vert_pad_size = Size.Fixed(axes_pad[1])

Expand Down Expand Up @@ -265,9 +254,8 @@ def set_axes_pad(self, axes_pad):
axes_pad : (float, float)
The padding (horizontal pad, vertical pad) in inches.
"""
self._axes_pad = axes_pad

# These two lines actually differ from ones in _init_axes_pad
# Differs from _init_axes_pad by 1) not broacasting, 2) modifying the
# Size.Fixed objects in-place.
self._horiz_pad_size.fixed_size = axes_pad[0]
self._vert_pad_size.fixed_size = axes_pad[1]

Expand All @@ -280,7 +268,8 @@ def get_axes_pad(self):
hpad, vpad
Padding (horizontal pad, vertical pad) in inches.
"""
return self._axes_pad
return (self._horiz_pad_size.fixed_size,
self._vert_pad_size.fixed_size)

def set_aspect(self, aspect):
"""Set the aspect of the SubplotDivider."""
Expand Down Expand Up @@ -410,8 +399,7 @@ def __init__(self, fig,
cbar_set_cax : bool, default: True
If True, each axes in the grid has a *cax* attribute that is bound
to associated *cbar_axes*.
axes_class : a type that is a subclass of `matplotlib.axes.Axes`, \
default: None
axes_class : subclass of `matplotlib.axes.Axes`, default: None
"""
self._nrows, self._ncols = nrows_ncols

Expand All @@ -423,24 +411,21 @@ def __init__(self, fig,

self.ngrids = ngrids

axes_pad = _extend_axes_pad(axes_pad)
self._axes_pad = axes_pad
self._init_axes_pad(axes_pad)

self._colorbar_mode = cbar_mode
self._colorbar_location = cbar_location
if cbar_pad is None:
# horizontal or vertical arrangement?
if cbar_location in ("left", "right"):
self._colorbar_pad = axes_pad[0]
self._colorbar_pad = self._horiz_pad_size.fixed_size
else:
self._colorbar_pad = axes_pad[1]
self._colorbar_pad = self._vert_pad_size.fixed_size
else:
self._colorbar_pad = cbar_pad

self._colorbar_size = cbar_size

self._init_axes_pad(axes_pad)

cbook._check_in_list(["column", "row"], direction=direction)
self._direction = direction

Expand Down Expand Up @@ -528,7 +513,7 @@ def _update_locators(self):

for col, ax in enumerate(self.axes_row[0]):
if h:
h.append(self._horiz_pad_size) # Size.Fixed(self._axes_pad))
h.append(self._horiz_pad_size)

if ax:
sz = Size.AxesX(ax, aspect="axes", ref_ax=self.axes_all[0])
Expand Down Expand Up @@ -559,7 +544,7 @@ def _update_locators(self):
v_cb_pos = []
for row, ax in enumerate(self.axes_column[0][::-1]):
if v:
v.append(self._vert_pad_size) # Size.Fixed(self._axes_pad))
v.append(self._vert_pad_size)

if ax:
sz = Size.AxesY(ax, aspect="axes", ref_ax=self.axes_all[0])
Expand Down