Skip to content

Commit 657ad7d

Browse files
committed
Unconvert bounds when drawing Line2D
1 parent 79acf30 commit 657ad7d

File tree

2 files changed

+41
-12
lines changed

2 files changed

+41
-12
lines changed

lib/matplotlib/axes/_base.py

+40-11
Original file line numberDiff line numberDiff line change
@@ -2987,9 +2987,16 @@ def xaxis_inverted(self):
29872987
left, right = self.get_xlim()
29882988
return right < left
29892989

2990-
def get_xbound(self):
2991-
"""Return the lower and upper x-axis bounds, in increasing order."""
2992-
left, right = self.get_xlim()
2990+
def get_xbound(self, units=True):
2991+
"""
2992+
Return the lower and upper x-axis bounds, in increasing order.
2993+
2994+
Parameters
2995+
----------
2996+
units : bool, optional
2997+
If *True*, return bounds with units attached.
2998+
"""
2999+
left, right = self.get_xlim(units)
29933000
if left < right:
29943001
return left, right
29953002
else:
@@ -3025,10 +3032,15 @@ def set_xbound(self, lower=None, upper=None):
30253032
else:
30263033
self.set_xlim(upper, lower, auto=None)
30273034

3028-
def get_xlim(self):
3035+
def get_xlim(self, units=True):
30293036
"""
30303037
Get the x-axis range
30313038
3039+
Parameters
3040+
----------
3041+
units : bool, optional
3042+
If *True*, return limits with units attached.
3043+
30323044
Returns
30333045
-------
30343046
xlimits : tuple
@@ -3041,7 +3053,10 @@ def get_xlim(self):
30413053
be greater than the `right` value.
30423054
30433055
"""
3044-
return self._convert_back_lim(self.viewLim.intervalx, self.xaxis)
3056+
if units:
3057+
return self._convert_back_lim(self.viewLim.intervalx, self.xaxis)
3058+
else:
3059+
return tuple(self.viewLim.intervalx)
30453060

30463061
def _convert_back_lim(self, lim, axis):
30473062
"""
@@ -3349,9 +3364,16 @@ def yaxis_inverted(self):
33493364
bottom, top = self.get_ylim()
33503365
return top < bottom
33513366

3352-
def get_ybound(self):
3353-
"""Return the lower and upper y-axis bounds, in increasing order."""
3354-
bottom, top = self.get_ylim()
3367+
def get_ybound(self, units=True):
3368+
"""
3369+
Return the lower and upper y-axis bounds, in increasing order.
3370+
3371+
Parameters
3372+
----------
3373+
units : bool, optional
3374+
If *True*, return bounds with units attached.
3375+
"""
3376+
bottom, top = self.get_ylim(units)
33553377
if bottom < top:
33563378
return bottom, top
33573379
else:
@@ -3386,10 +3408,15 @@ def set_ybound(self, lower=None, upper=None):
33863408
else:
33873409
self.set_ylim(upper, lower, auto=None)
33883410

3389-
def get_ylim(self):
3411+
def get_ylim(self, units=True):
33903412
"""
33913413
Get the y-axis range
33923414
3415+
Parameters
3416+
----------
3417+
units : bool, optional
3418+
If *True*, return bounds with units attached.
3419+
33933420
Returns
33943421
-------
33953422
ylimits : tuple
@@ -3402,8 +3429,10 @@ def get_ylim(self):
34023429
will be greater than the `top` value.
34033430
34043431
"""
3405-
return self._convert_back_lim(self.viewLim.intervaly, self.yaxis)
3406-
return tuple(self.viewLim.intervaly)
3432+
if units:
3433+
return self._convert_back_lim(self.viewLim.intervaly, self.yaxis)
3434+
else:
3435+
return tuple(self.viewLim.intervaly)
34073436

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

lib/matplotlib/lines.py

+1-1
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)