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 3b727b6

Browse filesBrowse files
committed
Support SubFigures in AxesDivider.
1 parent 178b46e commit 3b727b6
Copy full SHA for 3b727b6

File tree

Expand file treeCollapse file tree

4 files changed

+34
-33
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+34
-33
lines changed

‎examples/axes_grid1/simple_axes_divider1.py

Copy file name to clipboardExpand all lines: examples/axes_grid1/simple_axes_divider1.py
+18-19Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
=====================
33
Simple Axes Divider 1
44
=====================
5+
6+
See also :doc:`/tutorials/toolkits/axes_grid`.
57
"""
68

79
from mpl_toolkits.axes_grid1 import Size, Divider
@@ -16,51 +18,48 @@ def label_axes(ax, text):
1618
left=False, labelleft=False)
1719

1820

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

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

25+
sfs[0].suptitle("Fixed axes sizes, fixed paddings")
2526
# Sizes are in inches.
2627
horiz = [Size.Fixed(1.), Size.Fixed(.5), Size.Fixed(1.5), Size.Fixed(.5)]
2728
vert = [Size.Fixed(1.5), Size.Fixed(.5), Size.Fixed(1.)]
2829

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

3334
# 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))
35+
ax1 = sfs[0].add_axes(rect, axes_locator=div.new_locator(nx=0, ny=0))
3536
label_axes(ax1, "nx=0, ny=0")
36-
ax2 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=0, ny=2))
37+
ax2 = sfs[0].add_axes(rect, axes_locator=div.new_locator(nx=0, ny=2))
3738
label_axes(ax2, "nx=0, ny=2")
38-
ax3 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=2, ny=2))
39+
ax3 = sfs[0].add_axes(rect, axes_locator=div.new_locator(nx=2, ny=2))
3940
label_axes(ax3, "nx=2, ny=2")
40-
ax4 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=2, nx1=4, ny=0))
41+
ax4 = sfs[0].add_axes(rect, axes_locator=div.new_locator(nx=2, nx1=4, ny=0))
4142
label_axes(ax4, "nx=2, nx1=4, ny=0")
4243

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")
4844

45+
sfs[1].suptitle("Scalable axes sizes, fixed paddings")
46+
# Fixed sizes are in inches, scaled sizes are relative.
4947
horiz = [Size.Scaled(1.5), Size.Fixed(.5), Size.Scaled(1.), Size.Scaled(.5)]
5048
vert = [Size.Scaled(1.), Size.Fixed(.5), Size.Scaled(1.5)]
5149

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

5654
# 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))
55+
ax1 = sfs[1].add_axes(rect, axes_locator=div.new_locator(nx=0, ny=0))
5856
label_axes(ax1, "nx=0, ny=0")
59-
ax2 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=0, ny=2))
57+
ax2 = sfs[1].add_axes(rect, axes_locator=div.new_locator(nx=0, ny=2))
6058
label_axes(ax2, "nx=0, ny=2")
61-
ax3 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=2, ny=2))
59+
ax3 = sfs[1].add_axes(rect, axes_locator=div.new_locator(nx=2, ny=2))
6260
label_axes(ax3, "nx=2, ny=2")
63-
ax4 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=2, nx1=4, ny=0))
61+
ax4 = sfs[1].add_axes(rect, axes_locator=div.new_locator(nx=2, nx1=4, ny=0))
6462
label_axes(ax4, "nx=2, nx1=4, ny=0")
6563

64+
6665
plt.show()

‎examples/axes_grid1/simple_axes_divider3.py

Copy file name to clipboardExpand all lines: examples/axes_grid1/simple_axes_divider3.py
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
Simple Axes Divider 3
44
=====================
55
6+
See also :doc:`/tutorials/toolkits/axes_grid`.
67
"""
8+
79
import mpl_toolkits.axes_grid1.axes_size as Size
810
from mpl_toolkits.axes_grid1 import Divider
911
import matplotlib.pyplot as plt

‎lib/mpl_toolkits/axes_grid1/axes_divider.py

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

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

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

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

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

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

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

@@ -657,18 +657,18 @@ def _locate(self, x, y, w, h,
657657

658658
def locate(self, nx, ny, nx1=None, ny1=None, axes=None, renderer=None):
659659
# docstring inherited
660-
figW, figH = 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

663663
y_equivalent_sizes = self.get_vertical_sizes(renderer)
664664
x_appended_sizes = self.get_horizontal_sizes(renderer)
665665
x0, y0, ox, hh = self._locate(x, y, w, h,
666666
y_equivalent_sizes, x_appended_sizes,
667-
figW, figH)
667+
fig_w, fig_h)
668668
if nx1 is None:
669669
nx1 = nx + 1
670670

671-
x1, w1 = x0 + ox[nx] / figW, (ox[nx1] - ox[nx]) / figW
671+
x1, w1 = x0 + ox[nx] / fig_w, (ox[nx1] - ox[nx]) / fig_w
672672
y1, h1 = y0, hh
673673

674674
return mtransforms.Bbox.from_bounds(x1, y1, w1, h1)
@@ -695,19 +695,19 @@ def new_locator(self, ny, ny1=None):
695695

696696
def locate(self, nx, ny, nx1=None, ny1=None, axes=None, renderer=None):
697697
# docstring inherited
698-
figW, figH = self._fig.get_size_inches()
698+
fig_w, fig_h = self._fig.bbox.size / self._fig.dpi
699699
x, y, w, h = self.get_position_runtime(axes, renderer)
700700

701701
x_equivalent_sizes = self.get_horizontal_sizes(renderer)
702702
y_appended_sizes = self.get_vertical_sizes(renderer)
703703
y0, x0, oy, ww = self._locate(y, x, h, w,
704704
x_equivalent_sizes, y_appended_sizes,
705-
figH, figW)
705+
fig_h, fig_w)
706706
if ny1 is None:
707707
ny1 = ny + 1
708708

709709
x1, w1 = x0, ww
710-
y1, h1 = y0 + oy[ny] / figH, (oy[ny1] - oy[ny]) / figH
710+
y1, h1 = y0 + oy[ny] / fig_h, (oy[ny1] - oy[ny]) / fig_h
711711

712712
return mtransforms.Bbox.from_bounds(x1, y1, w1, h1)
713713

‎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.