Skip to content

Commit cf44eb7

Browse files
committed
fix(comment): #28701 make FillBetweenPolyCollection._update_axes_datalim @timhoffm #28702 (comment)
1 parent 187dd6e commit cf44eb7

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5599,14 +5599,7 @@ def _fill_between_x_or_y(
55995599
"""
56005600
collection = mcoll.FillBetweenPolyCollection(
56015601
ind_dir, ind, dep1, dep2,
5602-
where=where, interpolate=interpolate, step=step, _axes=self, **kwargs)
5603-
5604-
# now update the datalim and autoscale
5605-
up_x = up_y = True
5606-
if up_xy := getattr(collection, "_up_xy", None):
5607-
up_x, up_y = up_xy(self.transData)
5608-
5609-
self.update_datalim(collection._pts, updatex=up_x, updatey=up_y)
5602+
where=where, interpolate=interpolate, step=step, axes=self, **kwargs)
56105603

56115604
self.add_collection(collection, autolim=False)
56125605
self._request_autoscale_view()

lib/matplotlib/collections.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,12 +1258,14 @@ def set_verts_and_codes(self, verts, codes):
12581258
class FillBetweenPolyCollection(PolyCollection):
12591259
def __init__(
12601260
self, t_direction, t, f1, f2, *,
1261-
where=None, interpolate=False, step=None, _axes=None, **kwargs):
1261+
where=None, interpolate=False, step=None, axes=None, **kwargs):
12621262
self.t_direction = t_direction
1263-
kwargs = self._normalise_kwargs(_axes, **kwargs)
1263+
kwargs = self._normalise_kwargs(axes, **kwargs)
12641264
polys = self._make_verts(
1265-
t, f1, f2, where, interpolate, step, _axes, **kwargs)
1265+
t, f1, f2, where, interpolate, step, axes, **kwargs)
12661266
super().__init__(polys, **kwargs)
1267+
if axes is not None:
1268+
self._update_axes_datalim(axes, kwargs.get("transform"))
12671269

12681270
@property
12691271
def _f_direction(self):
@@ -1317,9 +1319,6 @@ def _make_verts(self, t, f1, f2, where, interpolate, step, axes, **kwargs):
13171319
self._pts = self._normalise_pts(np.vstack([
13181320
np.hstack([t[where, None], dep[where, None]]) for dep in (f1, f2)]))
13191321

1320-
if "transform" in kwargs:
1321-
self._up_xy = kwargs["transform"].contains_branch_seperately
1322-
13231322
return polys
13241323

13251324
def _normalise_kwargs(self, axes, **kwargs):
@@ -1385,6 +1384,13 @@ def _get_interp_point(self, t, f1, f2, idx):
13851384
def _normalise_pts(self, pts):
13861385
return pts[:, ::-1] if self.t_direction == "y" else pts
13871386

1387+
def _update_axes_datalim(self, axes, transform):
1388+
"""Update the datalim and autoscale."""
1389+
if transform is not None:
1390+
up_x, up_y = transform.contains_branch_seperately(axes.transData)
1391+
else:
1392+
up_x = up_y = True
1393+
axes.update_datalim(self._pts, updatex=up_x, updatey=up_y)
13881394

13891395
class RegularPolyCollection(_CollectionWithSizes):
13901396
"""A collection of n-sided regular polygons."""

lib/matplotlib/collections.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class FillBetweenPolyCollection(PolyCollection):
120120
where: Sequence[bool] | None = ...,
121121
interpolate: bool = ...,
122122
step: Literal["pre", "post", "mid"] | None = ...,
123-
_axes: "Axes | None" = ...,
123+
axes: "Axes | None" = ...,
124124
**kwargs,
125125
) -> None: ...
126126
@property

0 commit comments

Comments
 (0)