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

Skip to content

Commit 8b78c90

Browse files
committed
Unconvert bounds when drawing Line2D
1 parent 1b0a71a commit 8b78c90

File tree

2 files changed

+41
-12
lines changed

2 files changed

+41
-12
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2996,9 +2996,16 @@ def xaxis_inverted(self):
29962996
left, right = self.get_xlim()
29972997
return right < left
29982998

2999-
def get_xbound(self):
3000-
"""Return the lower and upper x-axis bounds, in increasing order."""
3001-
left, right = self.get_xlim()
2999+
def get_xbound(self, units=True):
3000+
"""
3001+
Return the lower and upper x-axis bounds, in increasing order.
3002+
3003+
Parameters
3004+
----------
3005+
units : bool, optional
3006+
If *True*, return bounds with units attached.
3007+
"""
3008+
left, right = self.get_xlim(units)
30023009
if left < right:
30033010
return left, right
30043011
else:
@@ -3034,10 +3041,15 @@ def set_xbound(self, lower=None, upper=None):
30343041
else:
30353042
self.set_xlim(upper, lower, auto=None)
30363043

3037-
def get_xlim(self):
3044+
def get_xlim(self, units=True):
30383045
"""
30393046
Get the x-axis range
30403047
3048+
Parameters
3049+
----------
3050+
units : bool, optional
3051+
If *True*, return limits with units attached.
3052+
30413053
Returns
30423054
-------
30433055
xlimits : tuple
@@ -3050,7 +3062,10 @@ def get_xlim(self):
30503062
be greater than the `right` value.
30513063
30523064
"""
3053-
return self._convert_back_lim(self.viewLim.intervalx, self.xaxis)
3065+
if units:
3066+
return self._convert_back_lim(self.viewLim.intervalx, self.xaxis)
3067+
else:
3068+
return tuple(self.viewLim.intervalx)
30543069

30553070
def _convert_back_lim(self, lim, axis):
30563071
"""
@@ -3358,9 +3373,16 @@ def yaxis_inverted(self):
33583373
bottom, top = self.get_ylim()
33593374
return top < bottom
33603375

3361-
def get_ybound(self):
3362-
"""Return the lower and upper y-axis bounds, in increasing order."""
3363-
bottom, top = self.get_ylim()
3376+
def get_ybound(self, units=True):
3377+
"""
3378+
Return the lower and upper y-axis bounds, in increasing order.
3379+
3380+
Parameters
3381+
----------
3382+
units : bool, optional
3383+
If *True*, return bounds with units attached.
3384+
"""
3385+
bottom, top = self.get_ylim(units)
33643386
if bottom < top:
33653387
return bottom, top
33663388
else:
@@ -3395,10 +3417,15 @@ def set_ybound(self, lower=None, upper=None):
33953417
else:
33963418
self.set_ylim(upper, lower, auto=None)
33973419

3398-
def get_ylim(self):
3420+
def get_ylim(self, units=True):
33993421
"""
34003422
Get the y-axis range
34013423
3424+
Parameters
3425+
----------
3426+
units : bool, optional
3427+
If *True*, return bounds with units attached.
3428+
34023429
Returns
34033430
-------
34043431
ylimits : tuple
@@ -3411,8 +3438,10 @@ def get_ylim(self):
34113438
will be greater than the `top` value.
34123439
34133440
"""
3414-
return self._convert_back_lim(self.viewLim.intervaly, self.yaxis)
3415-
return tuple(self.viewLim.intervaly)
3441+
if units:
3442+
return self._convert_back_lim(self.viewLim.intervaly, self.yaxis)
3443+
else:
3444+
return tuple(self.viewLim.intervaly)
34163445

34173446
def set_ylim(self, bottom=None, top=None, emit=True, auto=False,
34183447
*, ymin=None, ymax=None):

lib/matplotlib/lines.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ def draw(self, renderer):
760760
self.recache()
761761
self.ind_offset = 0 # Needed for contains() method.
762762
if self._subslice and self.axes:
763-
x0, x1 = self.axes.get_xbound()
763+
x0, x1 = self.axes.get_xbound(units=False)
764764
i0, = self._x_filled.searchsorted([x0], 'left')
765765
i1, = self._x_filled.searchsorted([x1], 'right')
766766
subslice = slice(max(i0 - 1, 0), i1 + 1)

0 commit comments

Comments
 (0)