Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1f0a994

Browse filesBrowse files
committed
Support SubFigures in AxesDivider.
1 parent f123ee8 commit 1f0a994
Copy full SHA for 1f0a994

File tree

Expand file treeCollapse file tree

3 files changed

+26
-29
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+26
-29
lines changed

‎examples/axes_grid1/simple_axes_divider1.py

Copy file name to clipboardExpand all lines: examples/axes_grid1/simple_axes_divider1.py
+16-19Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,51 +16,48 @@ def setup(ax, text):
1616
left=False, labelleft=False)
1717

1818

19-
##############################################################################
20-
# Fixed axes sizes; fixed paddings.
19+
fig = plt.figure(figsize=(12, 6))
20+
sfs = fig.subfigures(1, 2)
2121

22-
fig = plt.figure(figsize=(6, 6))
23-
fig.suptitle("Fixed axes sizes, fixed paddings")
2422

23+
sfs[0].suptitle("Fixed axes sizes, fixed paddings")
2524
# Sizes are in inches.
2625
horiz = [Size.Fixed(1.), Size.Fixed(.5), Size.Fixed(1.5), Size.Fixed(.5)]
2726
vert = [Size.Fixed(1.5), Size.Fixed(.5), Size.Fixed(1.)]
2827

2928
rect = (0.1, 0.1, 0.8, 0.8)
3029
# Divide the axes rectangle into a grid with sizes specified by horiz * vert.
31-
divider = Divider(fig, rect, horiz, vert, aspect=False)
30+
div = Divider(sfs[0], rect, horiz, vert, aspect=False)
3231

3332
# The rect parameter will actually be ignored and overridden by axes_locator.
34-
ax1 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=0, ny=0))
33+
ax1 = sfs[0].add_axes(rect, axes_locator=div.new_locator(nx=0, ny=0))
3534
setup(ax1, "nx=0, ny=0")
36-
ax2 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=0, ny=2))
35+
ax2 = sfs[0].add_axes(rect, axes_locator=div.new_locator(nx=0, ny=2))
3736
setup(ax2, "nx=0, ny=2")
38-
ax3 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=2, ny=2))
37+
ax3 = sfs[0].add_axes(rect, axes_locator=div.new_locator(nx=2, ny=2))
3938
setup(ax3, "nx=2, ny=2")
40-
ax4 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=2, nx1=4, ny=0))
39+
ax4 = sfs[0].add_axes(rect, axes_locator=div.new_locator(nx=2, nx1=4, ny=0))
4140
setup(ax4, "nx=2, nx1=4, ny=0")
4241

43-
##############################################################################
44-
# Axes sizes that scale with the figure size; fixed paddings.
45-
46-
fig = plt.figure(figsize=(6, 6))
47-
fig.suptitle("Scalable axes sizes, fixed paddings")
4842

43+
sfs[1].suptitle("Scalable axes sizes, fixed paddings")
44+
# Fixed sizes are in inches, scaled sizes are relative.
4945
horiz = [Size.Scaled(1.5), Size.Fixed(.5), Size.Scaled(1.), Size.Scaled(.5)]
5046
vert = [Size.Scaled(1.), Size.Fixed(.5), Size.Scaled(1.5)]
5147

5248
rect = (0.1, 0.1, 0.8, 0.8)
5349
# Divide the axes rectangle into a grid with sizes specified by horiz * vert.
54-
divider = Divider(fig, rect, horiz, vert, aspect=False)
50+
div = Divider(sfs[1], rect, horiz, vert, aspect=False)
5551

5652
# The rect parameter will actually be ignored and overridden by axes_locator.
57-
ax1 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=0, ny=0))
53+
ax1 = sfs[1].add_axes(rect, axes_locator=div.new_locator(nx=0, ny=0))
5854
setup(ax1, "nx=0, ny=0")
59-
ax2 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=0, ny=2))
55+
ax2 = sfs[1].add_axes(rect, axes_locator=div.new_locator(nx=0, ny=2))
6056
setup(ax2, "nx=0, ny=2")
61-
ax3 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=2, ny=2))
57+
ax3 = sfs[1].add_axes(rect, axes_locator=div.new_locator(nx=2, ny=2))
6258
setup(ax3, "nx=2, ny=2")
63-
ax4 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=2, nx1=4, ny=0))
59+
ax4 = sfs[1].add_axes(rect, axes_locator=div.new_locator(nx=2, nx1=4, ny=0))
6460
setup(ax4, "nx=2, nx1=4, ny=0")
6561

62+
6663
plt.show()

‎lib/mpl_toolkits/axes_grid1/axes_divider.py

Copy file name to clipboardExpand all lines: lib/mpl_toolkits/axes_grid1/axes_divider.py
+9-9Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -195,21 +195,21 @@ def locate(self, nx, ny, nx1=None, ny1=None, axes=None, renderer=None):
195195
renderer
196196
"""
197197

198-
figW, figH = self._fig.get_size_inches()
198+
fig_w, fig_h = self._fig.bbox.size / self._fig.dpi
199199
x, y, w, h = self.get_position_runtime(axes, renderer)
200200

201201
hsizes = self.get_horizontal_sizes(renderer)
202202
vsizes = self.get_vertical_sizes(renderer)
203-
k_h = self._calc_k(hsizes, figW*w)
204-
k_v = self._calc_k(vsizes, figH*h)
203+
k_h = self._calc_k(hsizes, fig_w*w)
204+
k_v = self._calc_k(vsizes, fig_h*h)
205205

206206
if self.get_aspect():
207207
k = min(k_h, k_v)
208208
ox = self._calc_offsets(hsizes, k)
209209
oy = self._calc_offsets(vsizes, k)
210210

211-
ww = (ox[-1] - ox[0]) / figW
212-
hh = (oy[-1] - oy[0]) / figH
211+
ww = (ox[-1] - ox[0]) / fig_w
212+
hh = (oy[-1] - oy[0]) / fig_h
213213
pb = mtransforms.Bbox.from_bounds(x, y, w, h)
214214
pb1 = mtransforms.Bbox.from_bounds(x, y, ww, hh)
215215
pb1_anchored = pb1.anchored(self.get_anchor(), pb)
@@ -225,8 +225,8 @@ def locate(self, nx, ny, nx1=None, ny1=None, axes=None, renderer=None):
225225
if ny1 is None:
226226
ny1 = ny + 1
227227

228-
x1, w1 = x0 + ox[nx] / figW, (ox[nx1] - ox[nx]) / figW
229-
y1, h1 = y0 + oy[ny] / figH, (oy[ny1] - oy[ny]) / figH
228+
x1, w1 = x0 + ox[nx] / fig_w, (ox[nx1] - ox[nx]) / fig_w
229+
y1, h1 = y0 + oy[ny] / fig_h, (oy[ny1] - oy[ny]) / fig_h
230230

231231
return mtransforms.Bbox.from_bounds(x1, y1, w1, h1)
232232

@@ -657,7 +657,7 @@ def new_locator(self, nx, nx1=None):
657657

658658
def locate(self, nx, ny, nx1=None, ny1=None, axes=None, renderer=None):
659659
# docstring inherited
660-
fig_w, fig_h = self._fig.get_size_inches()
660+
fig_w, fig_h = self._fig.bbox.size / self._fig.dpi
661661
x, y, w, h = self.get_position_runtime(axes, renderer)
662662
y_equal_sizes = self.get_vertical_sizes(renderer)
663663
x_summed_sizes = self.get_horizontal_sizes(renderer)
@@ -693,7 +693,7 @@ def new_locator(self, ny, ny1=None):
693693

694694
def locate(self, nx, ny, nx1=None, ny1=None, axes=None, renderer=None):
695695
# docstring inherited
696-
fig_w, fig_h = self._fig.get_size_inches()
696+
fig_w, fig_h = self._fig.bbox.size / self._fig.dpi
697697
x, y, w, h = self.get_position_runtime(axes, renderer)
698698
x_equal_sizes = self.get_horizontal_sizes(renderer)
699699
y_summed_sizes = self.get_vertical_sizes(renderer)

‎tutorials/toolkits/axes_grid.py

Copy file name to clipboardExpand all lines: tutorials/toolkits/axes_grid.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@
392392
393393
See the example,
394394
395-
.. figure:: ../../gallery/axes_grid1/images/sphx_glr_simple_axes_divider1_002.png
395+
.. figure:: ../../gallery/axes_grid1/images/sphx_glr_simple_axes_divider1_001.png
396396
:target: ../../gallery/axes_grid1/simple_axes_divider1.html
397397
:align: center
398398
:scale: 50

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.