Skip to content

Commit

Permalink
DOC: change name, add to api list...
Browse files Browse the repository at this point in the history
  • Loading branch information
jklymak committed Jun 18, 2018
1 parent 5baf6ac commit 8a7a7f7
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 47 deletions.
3 changes: 3 additions & 0 deletions doc/api/axes_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ Text and Annotations
Axes.text
Axes.table
Axes.arrow
Axes.inset_axes_from_lbwh
Axes.indicate_inset_lbwh
Axes.indicate_inset_zoom


Fields
Expand Down
8 changes: 4 additions & 4 deletions examples/subplots_axes_and_figures/zoom_inset_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def get_demo_image():
origin="lower")

# inset axes....
axins = ax.inset_axes_rect([0.5, 0.5, 0.47, 0.47])
axins = ax.inset_axes_from_lbwh([0.5, 0.5, 0.47, 0.47])
axins.imshow(Z2, extent=extent, interpolation="nearest",
origin="lower")
# sub region of the original image
Expand All @@ -41,7 +41,7 @@ def get_demo_image():
axins.set_xticklabels('')
axins.set_yticklabels('')

ax.zoom_inset_indicator(axins)
ax.indicate_inset_zoom(axins)

plt.show()

Expand All @@ -55,6 +55,6 @@ def get_demo_image():
# The use of the following functions and methods is shown in this example:

import matplotlib
matplotlib.axes.Axes.inset_axes_rect
matplotlib.axes.Axes.zoom_inset_indicator
matplotlib.axes.Axes.inset_axes_from_lbwh
matplotlib.axes.Axes.indicate_inset_zoom
matplotlib.axes.Axes.imshow
99 changes: 59 additions & 40 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,10 @@ def _plot_args_replacer(args, data):
"supported due to ambiguity of arguments.\nUse "
"multiple plotting calls instead.")


def _make_inset_locator(rect, trans, parent):
"""
Helper function to locate inset axes, used in `.Axes.inset_axes`.
Helper function to locate inset axes, used in `.Axes.inset_axes_from_lbwh`.
A locator gets used in `Axes.set_aspect` to override the default
locations... It is a function that takes an axes object and
Expand Down Expand Up @@ -410,15 +411,20 @@ def legend(self, *args, **kwargs):
def _remove_legend(self, legend):
self.legend_ = None

def inset_axes_rect(self, rect, *, transform=None, zorder=5,
def inset_axes_from_lbwh(self, lbwh, *, transform=None, zorder=5,
**kwargs):
"""
Add a child inset axes to this existing axes.
Warnings
--------
This method is experimental as of 3.0, and the API may change.
Parameters
----------
rect : [x0, y0, width, height]
lbwh : [x0, y0, width, height]
Lower-left corner of inset axes, and its width and height.
transform : `.Transform`
Expand All @@ -430,15 +436,15 @@ def inset_axes_rect(self, rect, *, transform=None, zorder=5,
to change whether it is above or below data plotted on the
parent axes.
Other Parameters
----------------
**kwargs
Other *kwargs* are passed on to the `axes.Axes` child axes.
Other *kwargs* are passed on to the `axes.Axes` child axes.
Returns
-------
New `.axes.Axes` instance.
Axes
The created `.axes.Axes` instance.
Examples
--------
Expand All @@ -448,16 +454,17 @@ def inset_axes_rect(self, rect, *, transform=None, zorder=5,
fig, ax = plt.suplots()
ax.plot(range(10))
axin1 = ax.inset_axes([0.8, 0.1, 0.15, 0.15])
axin2 = ax.inset_axes([5, 7, 2.3, 2.3], transform=ax.transData)
axin1 = ax.inset_axes_from_lbwh([0.8, 0.1, 0.15, 0.15])
axin2 = ax.inset_axes_from_lbwh(
[5, 7, 2.3, 2.3], transform=ax.transData)
"""
if transform is None:
transform = self.transAxes
label = kwargs.pop('label', 'inset_axes')
label = kwargs.pop('label', 'inset_axes_from_lbwh')

# This puts the rectangle into figure-relative coordinates.
inset_locator = _make_inset_locator(rect, transform, self)
inset_locator = _make_inset_locator(lbwh, transform, self)
bb = inset_locator(None, None)

inset_ax = Axes(self.figure, bb.bounds, zorder=zorder,
Expand All @@ -471,18 +478,24 @@ def inset_axes_rect(self, rect, *, transform=None, zorder=5,

return inset_ax

def inset_indicator(self, rect, inset_ax=None, *, transform=None,
def indicate_inset_lbwh(self, lbwh, inset_ax=None, *, transform=None,
facecolor='none', edgecolor='0.5', alpha=0.5,
zorder=4.99, **kwargs):
"""
Add an inset indicator to the axes. This is a rectangle on the plot
at the position indicated by *rect* that optionally has lines that
connect the rectangle to an inset axes (`.Axes.inset_axes`).
at the position indicated by *lbwh* that optionally has lines that
connect the rectangle to an inset axes (`.Axes.inset_axes_from_lbwh`).
Warnings
--------
This method is experimental as of 3.0, and the API may change.
Parameters
----------
rect : [x0, y0, width, height]
lbwh : [x0, y0, width, height]
Lower-left corner of rectangle to be marked, and its width
and height.
Expand All @@ -507,21 +520,21 @@ def inset_indicator(self, rect, inset_ax=None, *, transform=None,
Transparency of the rectangle and connector lines. Default is 0.5.
zorder : number
drawing order of the rectangle and connector lines. Default is 4.99
Drawing order of the rectangle and connector lines. Default is 4.99
(just below the default level of inset axes).
Other Parameters
----------------
Other *kwargs* are passed on to the rectangle patch.
**kwargs
Other *kwargs* are passed on to the rectangle patch.
Returns
-------
rectangle_patch, connector_lines :
`.Patches.Rectangle`, (four-tuple `.Patches.ConnectionPatch`) one
for each of four connector lines. Two are set with visibility to
*False*, but the user can set the visibility to True if the
rectangle_patch: `.Patches.Rectangle`
Rectangle artist.
connector_lines: 4-tuple of `.Patches.ConnectionPatch`
One for each of four connector lines. Two are set with visibility
to *False*, but the user can set the visibility to True if the
automatic choice is not deemed correct.
"""
Expand All @@ -532,10 +545,10 @@ def inset_indicator(self, rect, inset_ax=None, *, transform=None,

if transform is None:
transform = self.transData
label = kwargs.pop('label', 'inset_indicator')
label = kwargs.pop('label', 'indicate_inset_lbwh')

xy = (rect[0], rect[1])
rectpatch = mpatches.Rectangle(xy, rect[2], rect[3],
xy = (lbwh[0], lbwh[1])
rectpatch = mpatches.Rectangle(xy, lbwh[2], lbwh[3],
facecolor=facecolor, edgecolor=edgecolor, alpha=alpha,
zorder=zorder, label=label, transform=transform, **kwargs)
self.add_patch(rectpatch)
Expand All @@ -546,8 +559,8 @@ def inset_indicator(self, rect, inset_ax=None, *, transform=None,
pos = inset_ax.get_position() # this is in fig-fraction.
coordsA = 'axes fraction'
connects = []
xr = [rect[0], rect[0]+rect[2]]
yr = [rect[1], rect[1]+rect[3]]
xr = [lbwh[0], lbwh[0]+lbwh[2]]
yr = [lbwh[1], lbwh[1]+lbwh[3]]
for xc in range(2):
for yc in range(2):
xyA = (xc, yc)
Expand All @@ -561,7 +574,7 @@ def inset_indicator(self, rect, inset_ax=None, *, transform=None,
pos = inset_ax.get_position()
bboxins = pos.transformed(self.figure.transFigure)
rectbbox = mtransforms.Bbox.from_bounds(
*rect).transformed(transform)
*lbwh).transformed(transform)
if rectbbox.x0 < bboxins.x0:
sig = 1
else:
Expand All @@ -575,12 +588,17 @@ def inset_indicator(self, rect, inset_ax=None, *, transform=None,

return rectpatch, connects

def zoom_inset_indicator(self, inset_ax, **kwargs):
def indicate_inset_zoom(self, inset_ax, **kwargs):
"""
Add an inset indicator rectangle to the axes based on the axis
limits for an *inset_ax* and draw connectors between *inset_ax*
and the rectangle.
Warnings
--------
This method is experimental as of 3.0, and the API may change.
Parameters
----------
Expand All @@ -589,26 +607,27 @@ def zoom_inset_indicator(self, inset_ax, **kwargs):
drawn connecting the indicator box to the inset axes on corners
chosen so as to not overlap with the indicator box.
Other Parameters
----------------
Other *kwargs* are passed on to `.Axes.inset_rectangle`
**kwargs
Other *kwargs* are passed on to `.Axes.inset_rectangle`
Returns
-------
rectangle_patch, connector_lines :
`.Patches.Rectangle`, (four-tuple `.Patches.ConnectionPatch`) one
for each of four connector lines. Two are set with visibility to
*False*, but the user can set the visibility to True if the
rectangle_patch: `.Patches.Rectangle`
Rectangle artist.
connector_lines: 4-tuple of `.Patches.ConnectionPatch`
One for each of four connector lines. Two are set with visibility
to *False*, but the user can set the visibility to True if the
automatic choice is not deemed correct.
"""

xlim = inset_ax.get_xlim()
ylim = inset_ax.get_ylim()
rect = [xlim[0], ylim[0], xlim[1] - xlim[0], ylim[1] - ylim[0]]
rectpatch, connects = self.inset_indicator(rect, inset_ax, **kwargs)
rectpatch, connects = self.indicate_inset_lbwh(
rect, inset_ax, **kwargs)

return rectpatch, connects

Expand Down
6 changes: 3 additions & 3 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5743,15 +5743,15 @@ def test_zoom_inset():
ax.apply_aspect()
# we need to apply_aspect to make the drawing below work.

# Make the inset_axes... Position axes co-ordinates...
axin1 = ax.inset_axes_rect([0.7, 0.7, 0.35, 0.35])
# Make the inset_axes_from_lbwh... Position axes co-ordinates...
axin1 = ax.inset_axes_from_lbwh([0.7, 0.7, 0.35, 0.35])
# redraw the data in the inset axes...
axin1.pcolormesh(x, y, z)
axin1.set_xlim([1.5, 2.15])
axin1.set_ylim([2, 2.5])
axin1.set_aspect(ax.get_aspect())

rec, connectors = ax.zoom_inset_indicator(axin1)
rec, connectors = ax.indicate_inset_zoom(axin1)
fig.canvas.draw()
xx = np.array([[1.5, 2.],
[2.15, 2.5]])
Expand Down

0 comments on commit 8a7a7f7

Please sign in to comment.