-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
2d padding #2731
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
2d padding #2731
Changes from all commits
92f5e91
f5f44d9
b3c2148
17280cf
dd47eb7
3479b90
0ea50bb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,11 +14,18 @@ | |
import matplotlib.lines as mlines | ||
import matplotlib.ticker as ticker | ||
|
||
from matplotlib.gridspec import SubplotSpec, GridSpec | ||
from matplotlib.gridspec import SubplotSpec | ||
|
||
from .axes_divider import Size, SubplotDivider, LocatableAxes, Divider | ||
|
||
|
||
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 | ||
|
@@ -200,6 +207,8 @@ def __init__(self, fig, | |
================ ======== ========================================= | ||
direction "row" [ "row" | "column" ] | ||
axes_pad 0.02 float| pad between axes given in inches | ||
or tuple-like of floats, | ||
(horizontal padding, vertical padding) | ||
add_all True [ True | False ] | ||
share_all False [ True | False ] | ||
share_x True [ True | False ] | ||
|
@@ -238,8 +247,8 @@ def __init__(self, fig, | |
axes_class, axes_class_args = axes_class | ||
|
||
self.axes_all = [] | ||
self.axes_column = [[] for i in range(self._ncols)] | ||
self.axes_row = [[] for i in range(self._nrows)] | ||
self.axes_column = [[] for _ in range(self._ncols)] | ||
self.axes_row = [[] for _ in range(self._nrows)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why the variable change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because |
||
|
||
h = [] | ||
v = [] | ||
|
@@ -261,8 +270,8 @@ def __init__(self, fig, | |
rect = self._divider.get_position() | ||
|
||
# reference axes | ||
self._column_refax = [None for i in range(self._ncols)] | ||
self._row_refax = [None for i in range(self._nrows)] | ||
self._column_refax = [None for _ in range(self._ncols)] | ||
self._row_refax = [None for _ in range(self._nrows)] | ||
self._refax = None | ||
|
||
for i in range(self.ngrids): | ||
|
@@ -310,19 +319,19 @@ 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 | ||
|
||
self._horiz_pad_size = Size.Fixed(axes_pad) | ||
self._vert_pad_size = Size.Fixed(axes_pad) | ||
self._horiz_pad_size = Size.Fixed(axes_pad[0]) | ||
self._vert_pad_size = Size.Fixed(axes_pad[1]) | ||
|
||
def _update_locators(self): | ||
|
||
h = [] | ||
|
||
h_ax_pos = [] | ||
h_cb_pos = [] | ||
|
||
for ax in self._column_refax: | ||
for _ in self._column_refax: | ||
#if h: h.append(Size.Fixed(self._axes_pad)) | ||
if h: | ||
h.append(self._horiz_pad_size) | ||
|
@@ -335,8 +344,7 @@ def _update_locators(self): | |
v = [] | ||
|
||
v_ax_pos = [] | ||
v_cb_pos = [] | ||
for ax in self._row_refax[::-1]: | ||
for _ in self._row_refax[::-1]: | ||
#if v: v.append(Size.Fixed(self._axes_pad)) | ||
if v: | ||
v.append(self._vert_pad_size) | ||
|
@@ -362,6 +370,10 @@ def _get_col_row(self, n): | |
|
||
return col, row | ||
|
||
# Good to propagate __len__ if we have __getitem__ | ||
def __len__(self): | ||
return len(self.axes_all) | ||
|
||
def __getitem__(self, i): | ||
return self.axes_all[i] | ||
|
||
|
@@ -376,11 +388,19 @@ def set_axes_pad(self, axes_pad): | |
"set axes_pad" | ||
self._axes_pad = axes_pad | ||
|
||
self._horiz_pad_size.fixed_size = axes_pad | ||
self._vert_pad_size.fixed_size = axes_pad | ||
# These two lines actually differ from ones in _init_axes_pad | ||
self._horiz_pad_size.fixed_size = axes_pad[0] | ||
self._vert_pad_size.fixed_size = axes_pad[1] | ||
|
||
def get_axes_pad(self): | ||
"get axes_pad" | ||
""" | ||
get axes_pad | ||
|
||
Returns | ||
------- | ||
tuple | ||
Padding in inches, (horizontal pad, vertical pad) | ||
""" | ||
return self._axes_pad | ||
|
||
def set_aspect(self, aspect): | ||
|
@@ -484,6 +504,8 @@ def __init__(self, fig, | |
================ ======== ========================================= | ||
direction "row" [ "row" | "column" ] | ||
axes_pad 0.02 float| pad between axes given in inches | ||
or tuple-like of floats, | ||
(horizontal padding, vertical padding) | ||
add_all True [ True | False ] | ||
share_all False [ True | False ] | ||
aspect True [ True | False ] | ||
|
@@ -510,12 +532,17 @@ def __init__(self, fig, | |
|
||
self.ngrids = ngrids | ||
|
||
axes_pad = _extend_axes_pad(axes_pad) | ||
self._axes_pad = axes_pad | ||
|
||
self._colorbar_mode = cbar_mode | ||
self._colorbar_location = cbar_location | ||
if cbar_pad is None: | ||
self._colorbar_pad = axes_pad | ||
# horizontal or vertical arrangement? | ||
if cbar_location in ("left", "right"): | ||
self._colorbar_pad = axes_pad[0] | ||
else: | ||
self._colorbar_pad = axes_pad[1] | ||
else: | ||
self._colorbar_pad = cbar_pad | ||
|
||
|
@@ -538,8 +565,8 @@ def __init__(self, fig, | |
axes_class, axes_class_args = axes_class | ||
|
||
self.axes_all = [] | ||
self.axes_column = [[] for i in range(self._ncols)] | ||
self.axes_row = [[] for i in range(self._nrows)] | ||
self.axes_column = [[] for _ in range(self._ncols)] | ||
self.axes_row = [[] for _ in range(self._nrows)] | ||
|
||
self.cbar_axes = [] | ||
|
||
|
@@ -563,8 +590,8 @@ def __init__(self, fig, | |
rect = self._divider.get_position() | ||
|
||
# reference axes | ||
self._column_refax = [None for i in range(self._ncols)] | ||
self._row_refax = [None for i in range(self._nrows)] | ||
self._column_refax = [None for _ in range(self._ncols)] | ||
self._row_refax = [None for _ in range(self._nrows)] | ||
self._refax = None | ||
|
||
for i in range(self.ngrids): | ||
|
@@ -678,7 +705,7 @@ def _update_locators(self): | |
v_cb_pos = [] | ||
for row, ax in enumerate(self.axes_column[0][::-1]): | ||
if v: | ||
v.append(self._horiz_pad_size) # Size.Fixed(self._axes_pad)) | ||
v.append(self._vert_pad_size) # Size.Fixed(self._axes_pad)) | ||
|
||
if ax: | ||
sz = Size.AxesY(ax, aspect="axes", ref_ax=self.axes_all[0]) | ||
|
@@ -786,7 +813,7 @@ def _update_locators(self): | |
F.subplots_adjust(left=0.15, right=0.9) | ||
|
||
grid = Grid(F, 111, # similar to subplot(111) | ||
nrows_ncols = (2, 2), | ||
nrows_ncols=(2, 2), | ||
direction="row", | ||
axes_pad = 0.05, | ||
add_all=True, | ||
|
@@ -802,12 +829,12 @@ def _update_locators(self): | |
F.subplots_adjust(left=0.05, right=0.98) | ||
|
||
grid = ImageGrid(F, 131, # similar to subplot(111) | ||
nrows_ncols=(2, 2), | ||
direction="row", | ||
axes_pad = 0.05, | ||
add_all=True, | ||
label_mode = "1", | ||
) | ||
nrows_ncols=(2, 2), | ||
direction="row", | ||
axes_pad = 0.05, | ||
add_all=True, | ||
label_mode = "1", | ||
) | ||
|
||
Z, extent = get_demo_image() | ||
plt.ioff() | ||
|
@@ -821,14 +848,14 @@ def _update_locators(self): | |
plt.ion() | ||
|
||
grid = ImageGrid(F, 132, # similar to subplot(111) | ||
nrows_ncols=(2, 2), | ||
direction="row", | ||
axes_pad = 0.0, | ||
add_all=True, | ||
share_all=True, | ||
label_mode = "1", | ||
cbar_mode="single", | ||
) | ||
nrows_ncols=(2, 2), | ||
direction="row", | ||
axes_pad = 0.0, | ||
add_all=True, | ||
share_all=True, | ||
label_mode = "1", | ||
cbar_mode="single", | ||
) | ||
|
||
Z, extent = get_demo_image() | ||
plt.ioff() | ||
|
@@ -844,17 +871,17 @@ def _update_locators(self): | |
plt.ion() | ||
|
||
grid = ImageGrid(F, 133, # similar to subplot(122) | ||
nrows_ncols=(2, 2), | ||
direction="row", | ||
axes_pad = 0.1, | ||
add_all=True, | ||
label_mode = "1", | ||
share_all = True, | ||
cbar_location="top", | ||
cbar_mode="each", | ||
cbar_size="7%", | ||
cbar_pad="2%", | ||
) | ||
nrows_ncols=(2, 2), | ||
direction="row", | ||
axes_pad = 0.1, | ||
add_all=True, | ||
label_mode = "1", | ||
share_all = True, | ||
cbar_location="top", | ||
cbar_mode="each", | ||
cbar_size="7%", | ||
cbar_pad="2%", | ||
) | ||
plt.ioff() | ||
for i in range(4): | ||
im = grid[i].imshow(Z, extent=extent, interpolation="nearest") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are these changes here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
never mind, I understand now, sorry for the spam.