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

Skip to content

Commit 3cf7ea5

Browse files
author
Daniel Hyams
committed
Added a comment about the try/except block that catches malfunctions in
the _get_pixel_distance routines. Also added a warning emit, so that the try/catch at least says something if it is triggered.
1 parent 7e608d4 commit 3cf7ea5

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

lib/matplotlib/axis.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import matplotlib.transforms as mtransforms
1717
import matplotlib.units as munits
1818
import numpy as np
19+
import warnings
1920

2021
GRIDLINE_INTERPOLATION_STEPS = 180
2122

@@ -981,13 +982,19 @@ def _update_ticks(self, renderer):
981982
interval_expanded = interval[1], interval[0]
982983

983984
if hasattr(self, '_get_pixel_distance_along_axis'):
985+
# normally, one does not want to catch all exceptions that could possibly happen, but it
986+
# is not clear exactly what exceptions might arise from a user's projection (their rendition
987+
# of the Axis object). So, we catch all, with the idea that one would rather potentially
988+
# lose a tick from one side of the axis or another, rather than see a stack trace.
984989
try:
985990
ds1 = self._get_pixel_distance_along_axis(interval_expanded[0], -0.5)
986991
except:
992+
warnings.warn("Unable to find pixel distance along axis for interval padding; assuming no interval padding needed.")
987993
ds1 = 0.0
988994
try:
989995
ds2 = self._get_pixel_distance_along_axis(interval_expanded[1], +0.5)
990996
except:
997+
warnings.warn("Unable to find pixel distance along axis for interval padding; assuming no interval padding needed.")
991998
ds2 = 0.0
992999
interval_expanded = (interval[0] - ds1, interval[1] + ds2)
9931000

0 commit comments

Comments
 (0)