Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4e95320

Browse files
committed
Define FloatingAxes boundary patch in data coordinates.
Currently, the boundary patch of FloatingAxes is drawn in "parent axes data" (rectilinear) coordinates, using manual interpolation as defined in get_boundary. Instead, it can be defined in child axes data coordinates, and use `helper_trf + transData` as transform, relying on interpolation mechanisms already present in the transform machinery (for example, this means that polar FloatingAxes benefit from the more-accurate transforming of circular arcs). Likewise, adjust_axes_lim can use normal path methods to get its extents, rather than relying on manual interpolation. This is the cause of the baseline image tolerance change: in test_curvelinear3, for example, we now have exactly `bbox.xmin = bbox.ymin = -10` and `bbox.xmax = bbox.ymax = +10` rather than slightly different values arising from interpolation and inaccurate transform composition. (But one can manually check that the changes are all just tiny shifts.) (On the other hand, I'll likely further change these baselines in the future, so let's not update the files right now.)
1 parent 4723f8a commit 4e95320

File tree

3 files changed

+24
-17
lines changed

3 files changed

+24
-17
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
``floating_axes.GridHelperCurveLinear.get_boundary``
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
... is deprecated, with no replacement.

lib/mpl_toolkits/axisartist/floating_axes.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99

1010
import numpy as np
1111

12+
from matplotlib import _api
13+
import matplotlib.axes as maxes
1214
import matplotlib.patches as mpatches
1315
from matplotlib.path import Path
14-
import matplotlib.axes as maxes
1516

1617
from mpl_toolkits.axes_grid1.parasite_axes import host_axes_class_factory
1718

@@ -288,6 +289,7 @@ def get_gridlines(self, which="major", axis="both"):
288289
grid_lines.extend(self._grid_info["lat_lines"])
289290
return grid_lines
290291

292+
@_api.deprecated("3.5")
291293
def get_boundary(self):
292294
"""
293295
Return (N, 2) array of (x, y) coordinate of the boundary.
@@ -323,11 +325,19 @@ def __init__(self, *args, **kwargs):
323325

324326
def _gen_axes_patch(self):
325327
# docstring inherited
326-
return mpatches.Polygon(self.get_grid_helper().get_boundary())
328+
# Using a public API to access _extremes.
329+
(x0, _), (x1, _), (y0, _), (y1, _) = map(
330+
self.get_grid_helper().get_data_boundary,
331+
["left", "right", "bottom", "top"])
332+
patch = mpatches.Polygon([(x0, y0), (x1, y0), (x1, y1), (x0, y1)])
333+
patch.get_path()._interpolation_steps = 100
334+
return patch
327335

328336
def cla(self):
329337
super().cla()
330-
self.patch.set_transform(self.transData)
338+
self.patch.set_transform(
339+
self.get_grid_helper().grid_finder.get_transform()
340+
+ self.transData)
331341
# The original patch is not in the draw tree; it is only used for
332342
# clipping purposes.
333343
orig_patch = super()._gen_axes_patch()
@@ -337,18 +347,12 @@ def cla(self):
337347
self.gridlines.set_clip_path(orig_patch)
338348

339349
def adjust_axes_lim(self):
340-
grid_helper = self.get_grid_helper()
341-
t = grid_helper.get_boundary()
342-
x, y = t[:, 0], t[:, 1]
343-
344-
xmin, xmax = min(x), max(x)
345-
ymin, ymax = min(y), max(y)
346-
347-
dx = (xmax-xmin) / 100
348-
dy = (ymax-ymin) / 100
349-
350-
self.set_xlim(xmin-dx, xmax+dx)
351-
self.set_ylim(ymin-dy, ymax+dy)
350+
bbox = self.patch.get_path().get_extents(
351+
# First transform to pixel coords, then to parent data coords.
352+
self.patch.get_transform() - self.transData)
353+
bbox = bbox.expanded(1.02, 1.02)
354+
self.set_xlim(bbox.xmin, bbox.xmax)
355+
self.set_ylim(bbox.ymin, bbox.ymax)
352356

353357

354358
@functools.lru_cache(None)

lib/mpl_toolkits/tests/test_axisartist_floating_axes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def test_subplot():
1818
fig.add_subplot(ax)
1919

2020

21-
@image_comparison(['curvelinear3.png'], style='default', tol=0.01)
21+
@image_comparison(['curvelinear3.png'], style='default', tol=5)
2222
def test_curvelinear3():
2323
fig = plt.figure(figsize=(5, 5))
2424

@@ -72,7 +72,7 @@ def test_curvelinear3():
7272
l.set_clip_path(ax1.patch)
7373

7474

75-
@image_comparison(['curvelinear4.png'], style='default', tol=0.015)
75+
@image_comparison(['curvelinear4.png'], style='default', tol=0.9)
7676
def test_curvelinear4():
7777
# Remove this line when this test image is regenerated.
7878
plt.rcParams['text.kerning_factor'] = 6

0 commit comments

Comments
 (0)