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

Skip to content

Commit d1bd978

Browse files
Move domain check to axes
1 parent 371fcb2 commit d1bd978

3 files changed

Lines changed: 17 additions & 19 deletions

File tree

lib/matplotlib/artist.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -375,23 +375,6 @@ def get_window_extent(self, renderer=None):
375375
"""
376376
return Bbox([[0, 0], [0, 0]])
377377

378-
def _outside_axes_domain(self, x, y):
379-
"""
380-
Check if the data point (x, y) is outside the valid domain of the axes
381-
scales.
382-
383-
Returns True if the artist is in an Axes but the point is outside its
384-
data range (eg. negative coordinates with a log scale).
385-
"""
386-
ax = self.axes
387-
if ax is None:
388-
return False
389-
for val, axis in [(x, ax.xaxis), (y, ax.yaxis)]:
390-
vmin, vmax = axis.limit_range_for_scale(val, val)
391-
if vmin != val or vmax != val:
392-
return True
393-
return False
394-
395378
def get_tightbbox(self, renderer=None):
396379
"""
397380
Get the artist's bounding box in display space, taking clipping into account.

lib/matplotlib/axes/_base.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2443,6 +2443,20 @@ def _add_text(self, txt):
24432443
self.stale = True
24442444
return txt
24452445

2446+
def _point_in_data_domain(self, x, y):
2447+
"""
2448+
Check if the data point (x, y) is within the valid domain of the axes
2449+
scales.
2450+
2451+
Returns False if the point is outside the data range
2452+
(e.g. negative coordinates with a log scale).
2453+
"""
2454+
for val, axis in [(x, self.xaxis), (y, self.yaxis)]:
2455+
vmin, vmax = axis.limit_range_for_scale(val, val)
2456+
if vmin != val or vmax != val:
2457+
return False
2458+
return True
2459+
24462460
def _update_line_limits(self, line):
24472461
"""
24482462
Figures out the data limit of the given line, updating `.Axes.dataLim`.

lib/matplotlib/text.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,8 +1063,9 @@ def get_window_extent(self, renderer=None, dpi=None):
10631063
def get_tightbbox(self, renderer=None):
10641064
# Exclude text at data coordinates outside the valid domain of the axes
10651065
# scales (e.g., negative coordinates with a log scale).
1066-
if (self.axes and self.get_transform() == self.axes.transData # text is a data Artist
1067-
and self._outside_axes_domain(*self.get_unitless_position())):
1066+
if (self.axes
1067+
and self.get_transform() == self.axes.transData
1068+
and not self.axes._point_in_data_domain(*self.get_unitless_position())):
10681069
return Bbox.null()
10691070
return super().get_tightbbox(renderer)
10701071

0 commit comments

Comments
 (0)