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

Skip to content

Commit c9a8f22

Browse files
committed
FIX: remove along-pixel logic; not needed
1 parent 788eb72 commit c9a8f22

File tree

2 files changed

+9
-47
lines changed

2 files changed

+9
-47
lines changed

lib/matplotlib/axis.py

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,50 +1052,8 @@ def _update_ticks(self, renderer):
10521052
ihigh = locs[-1]
10531053
tick_tups = [ti for ti in tick_tups if ilow <= ti[1] <= ihigh]
10541054

1055-
# so that we don't lose ticks on the end, expand out the interval ever
1056-
# so slightly. The "ever so slightly" is defined to be the width of a
1057-
# half of a pixel. We don't want to draw a tick that even one pixel
1058-
# outside of the defined axis interval.
1059-
if interval[0] <= interval[1]:
1060-
interval_expanded = interval
1061-
else:
1062-
interval_expanded = interval[1], interval[0]
1063-
1064-
if hasattr(self, '_get_pixel_distance_along_axis'):
1065-
# normally, one does not want to catch all exceptions that
1066-
# could possibly happen, but it is not clear exactly what
1067-
# exceptions might arise from a user's projection (their
1068-
# rendition of the Axis object). So, we catch all, with
1069-
# the idea that one would rather potentially lose a tick
1070-
# from one side of the axis or another, rather than see a
1071-
# stack trace.
1072-
# We also catch users warnings here. These are the result of
1073-
# invalid numpy calculations that may be the result of out of
1074-
# bounds on axis with finite allowed intervals such as geo
1075-
# projections i.e. Mollweide.
1076-
with np.errstate(invalid='ignore'):
1077-
try:
1078-
ds1 = self._get_pixel_distance_along_axis(
1079-
interval_expanded[0], -0.5)
1080-
except Exception:
1081-
warnings.warn("Unable to find pixel distance along axis "
1082-
"for interval padding of ticks; assuming no "
1083-
"interval padding needed.")
1084-
ds1 = 0.0
1085-
if np.isnan(ds1):
1086-
ds1 = 0.0
1087-
try:
1088-
ds2 = self._get_pixel_distance_along_axis(
1089-
interval_expanded[1], +0.5)
1090-
except Exception:
1091-
warnings.warn("Unable to find pixel distance along axis "
1092-
"for interval padding of ticks; assuming no "
1093-
"interval padding needed.")
1094-
ds2 = 0.0
1095-
if np.isnan(ds2):
1096-
ds2 = 0.0
1097-
interval_expanded = (interval_expanded[0] - ds1,
1098-
interval_expanded[1] + ds2)
1055+
if interval[1] <= interval[0]:
1056+
interval = interval[1], interval[0]
10991057

11001058
ticks_to_draw = []
11011059
for tick, loc, label in tick_tups:
@@ -1105,7 +1063,7 @@ def _update_ticks(self, renderer):
11051063
tick.update_position(loc)
11061064
tick.set_label1(label)
11071065
tick.set_label2(label)
1108-
if not mtransforms.interval_contains(interval_expanded, loc):
1066+
if not mtransforms.interval_contains(interval, loc):
11091067
continue
11101068
ticks_to_draw.append(tick)
11111069

lib/matplotlib/transforms.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2892,7 +2892,7 @@ def nonsingular(vmin, vmax, expander=0.001, tiny=1e-15, increasing=True):
28922892
return vmin, vmax
28932893

28942894

2895-
def interval_contains(interval, val):
2895+
def interval_contains(interval, val, rtol=1e-10):
28962896
"""
28972897
Check, inclusively, whether an interval includes a given value.
28982898
@@ -2902,14 +2902,18 @@ def interval_contains(interval, val):
29022902
A 2-length sequence, endpoints that define the interval.
29032903
val : scalar
29042904
Value to check is within interval.
2905+
rtol : float
2906+
Floating point tolerance relatice to b-a. So tol = (b - a) * rtol, and
2907+
return True if a - tol <= val <= b + tol (for b>a).
29052908
29062909
Returns
29072910
-------
29082911
bool
29092912
Returns true if given val is within the interval.
29102913
"""
29112914
a, b = interval
2912-
return a <= val <= b or a >= val >= b
2915+
rtol = np.abs(b - a) * rtol
2916+
return a - rtol <= val <= b + rtol or a + rtol >= val >= b - rtol
29132917

29142918

29152919
def interval_contains_open(interval, val):

0 commit comments

Comments
 (0)