FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Support SubFigures in AxesDivider. by anntzer · Pull Request #20073 · matplotlib/matplotlib · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (4) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
37 changes: 18 additions & 19 deletions examples/axes_grid1/simple_axes_divider1.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
=====================
Simple Axes Divider 1
=====================

See also :doc:`/tutorials/toolkits/axes_grid`.
"""

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


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

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

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

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

# The rect parameter will actually be ignored and overridden by axes_locator.
ax1 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=0, ny=0))
ax1 = sfs[0].add_axes(rect, axes_locator=div.new_locator(nx=0, ny=0))
label_axes(ax1, "nx=0, ny=0")
ax2 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=0, ny=2))
ax2 = sfs[0].add_axes(rect, axes_locator=div.new_locator(nx=0, ny=2))
label_axes(ax2, "nx=0, ny=2")
ax3 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=2, ny=2))
ax3 = sfs[0].add_axes(rect, axes_locator=div.new_locator(nx=2, ny=2))
label_axes(ax3, "nx=2, ny=2")
ax4 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=2, nx1=4, ny=0))
ax4 = sfs[0].add_axes(rect, axes_locator=div.new_locator(nx=2, nx1=4, ny=0))
label_axes(ax4, "nx=2, nx1=4, ny=0")

##############################################################################
# Axes sizes that scale with the figure size; fixed paddings.

fig = plt.figure(figsize=(6, 6))
fig.suptitle("Scalable axes sizes, fixed paddings")

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

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

# The rect parameter will actually be ignored and overridden by axes_locator.
ax1 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=0, ny=0))
ax1 = sfs[1].add_axes(rect, axes_locator=div.new_locator(nx=0, ny=0))
label_axes(ax1, "nx=0, ny=0")
ax2 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=0, ny=2))
ax2 = sfs[1].add_axes(rect, axes_locator=div.new_locator(nx=0, ny=2))
label_axes(ax2, "nx=0, ny=2")
ax3 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=2, ny=2))
ax3 = sfs[1].add_axes(rect, axes_locator=div.new_locator(nx=2, ny=2))
label_axes(ax3, "nx=2, ny=2")
ax4 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=2, nx1=4, ny=0))
ax4 = sfs[1].add_axes(rect, axes_locator=div.new_locator(nx=2, nx1=4, ny=0))
label_axes(ax4, "nx=2, nx1=4, ny=0")


plt.show()
2 changes: 2 additions & 0 deletions examples/axes_grid1/simple_axes_divider3.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
Simple Axes Divider 3
=====================

See also :doc:`/tutorials/toolkits/axes_grid`.
"""

import mpl_toolkits.axes_grid1.axes_size as Size
from mpl_toolkits.axes_grid1 import Divider
import matplotlib.pyplot as plt
Expand Down
18 changes: 9 additions & 9 deletions lib/mpl_toolkits/axes_grid1/axes_divider.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -188,21 +188,21 @@ def locate(self, nx, ny, nx1=None, ny1=None, axes=None, renderer=None):
renderer
"""

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

hsizes = self.get_horizontal_sizes(renderer)
vsizes = self.get_vertical_sizes(renderer)
k_h = self._calc_k(hsizes, figW*w)
k_v = self._calc_k(vsizes, figH*h)
k_h = self._calc_k(hsizes, fig_w * w)
k_v = self._calc_k(vsizes, fig_h * h)

if self.get_aspect():
k = min(k_h, k_v)
ox = self._calc_offsets(hsizes, k)
oy = self._calc_offsets(vsizes, k)

ww = (ox[-1] - ox[0]) / figW
hh = (oy[-1] - oy[0]) / figH
ww = (ox[-1] - ox[0]) / fig_w
hh = (oy[-1] - oy[0]) / fig_h
pb = mtransforms.Bbox.from_bounds(x, y, w, h)
pb1 = mtransforms.Bbox.from_bounds(x, y, ww, hh)
pb1_anchored = pb1.anchored(self.get_anchor(), pb)
Expand All @@ -218,8 +218,8 @@ def locate(self, nx, ny, nx1=None, ny1=None, axes=None, renderer=None):
if ny1 is None:
ny1 = ny + 1

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

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

Expand Down Expand Up @@ -649,7 +649,7 @@ def new_locator(self, nx, nx1=None):

def locate(self, nx, ny, nx1=None, ny1=None, axes=None, renderer=None):
# docstring inherited
fig_w, fig_h = self._fig.get_size_inches()
fig_w, fig_h = self._fig.bbox.size / self._fig.dpi
x, y, w, h = self.get_position_runtime(axes, renderer)
summed_ws = self.get_horizontal_sizes(renderer)
equal_hs = self.get_vertical_sizes(renderer)
Expand Down Expand Up @@ -684,7 +684,7 @@ def new_locator(self, ny, ny1=None):

def locate(self, nx, ny, nx1=None, ny1=None, axes=None, renderer=None):
# docstring inherited
fig_w, fig_h = self._fig.get_size_inches()
fig_w, fig_h = self._fig.bbox.size / self._fig.dpi
x, y, w, h = self.get_position_runtime(axes, renderer)
summed_hs = self.get_vertical_sizes(renderer)
equal_ws = self.get_horizontal_sizes(renderer)
Expand Down
2 changes: 1 addition & 1 deletion tutorials/toolkits/axes_grid.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@

See the example,

.. figure:: ../../gallery/axes_grid1/images/sphx_glr_simple_axes_divider1_002.png
.. figure:: ../../gallery/axes_grid1/images/sphx_glr_simple_axes_divider1_001.png
:target: ../../gallery/axes_grid1/simple_axes_divider1.html
:align: center
:scale: 50
Expand Down

Back | FazBrowse Home | New Git URL