-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix lost ticks #1686
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix lost ticks #1686
Changes from 1 commit
255f213
4c0f3f3
63a40e4
1f3959d
a0a7998
82db1d6
e2a6f92
c1b9886
43929de
36ce184
7e608d4
3cf7ea5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
PEP8 fixes, and part of a comment changed to a docstring. Also added a try/except around each call to _get_pixel_distance_along_axis, so that if something goes wrong with some off-beat transform, we just don't pad; things revert back to old matplotlib behavior.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -978,12 +978,18 @@ def _update_ticks(self, renderer): | |
if interval[0] <= interval[1]: | ||
interval_expanded = interval | ||
else: | ||
interval_expanded = interval[1],interval[0] | ||
interval_expanded = interval[1], interval[0] | ||
|
||
if hasattr(self,'_get_pixel_distance_along_axis'): | ||
ds1 = self._get_pixel_distance_along_axis(interval_expanded[0],-1)/2.0 | ||
ds2 = self._get_pixel_distance_along_axis(interval_expanded[1],+1)/2.0 | ||
interval_expanded = (interval[0]-ds1,interval[1]+ds2) | ||
try: | ||
ds1 = self._get_pixel_distance_along_axis(interval_expanded[0],-1)/2.0 | ||
except: | ||
ds1 = 0.0 | ||
try: | ||
ds2 = self._get_pixel_distance_along_axis(interval_expanded[1],+1)/2.0 | ||
except: | ||
ds2 = 0.0 | ||
interval_expanded = (interval[0] - ds1, interval[1] + ds2) | ||
|
||
ticks_to_draw = [] | ||
for tick, loc, label in tick_tups: | ||
|
@@ -1613,26 +1619,26 @@ def _get_offset_text(self): | |
return offsetText | ||
|
||
def _get_pixel_distance_along_axis(self,where,perturb): | ||
# returns the amount, in data coordinates, that a single pixel corresponds to in the | ||
# locality given by "where", which is also given in data coordinates, and is an x coordinate. | ||
# "perturb" is the amount to perturb the pixel. Usually +1 or -1. | ||
""" | ||
Returns the amount, in data coordinates, that a single pixel corresponds to in the | ||
locality given by "where", which is also given in data coordinates, and is an x coordinate. | ||
"perturb" is the amount to perturb the pixel. Usually +1 or -1. | ||
""" | ||
|
||
# first figure out the pixel location of the "where" point. We use 1e-10 for the | ||
# y point, so that we remain compatible with log axes. | ||
# | ||
# Note that this routine does not work for a polar axis, because of the 1e-10 below. To | ||
# do things correctly, we need to use rmax instead of 1e-10 for a polar axis. But | ||
# since we do not have that kind of information at this point, we just don't try to | ||
# pad anything for the theta axis of a polar plot. | ||
# | ||
if self.axes.name == 'polar': | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't really like this approach. What if I wanted to implement my own projection and it didn't even have an inverted data transformation? The safer, though perhaps not best, option would be to make sure There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm; I think the approach is correct here...the only problem with the polar projection is the singularity at r=0, which is why it is specifically exempted. The code should activate for everything else. As for not having an inverted transformation, would that even make sense? Not being able to go from pixel coordinates to data coordinates? Seems like there would be quite a few other things that would break in that situation; not just this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think @pelson's point might be that it's not a great idea to single out a particular projection here -- the user can install and use any number of projections. I haven't given it much thought, but it would be great to find a way to detect this case other than just checking for polar. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The singling out, though, is for the one projection that I know it doesn't work for. It should work for others, but just for safety, in the latest commits, I wrapped a try/except around each call that gets the amount of padding to use, which defaults the padding to zero in the case of a problem. This recovers old matplotlib behavior. |
||
return 0.0 | ||
|
||
#first figure out the pixel location of the "where" point. We use 1e-10 for the | ||
#y point, so that we remain compatible with log axes. | ||
trans = self.axes.transData # transformation from data coords to display coords | ||
transinv = trans.inverted() # transformation from display coords to data coords | ||
pix = trans.transform_point((where,1e-10)) | ||
ptp = transinv.transform_point((pix[0]+perturb,pix[1])) # perturb the pixel. | ||
dx = abs(ptp[0]-where) | ||
pix = trans.transform_point((where, 1e-10)) | ||
ptp = transinv.transform_point((pix[0] + perturb, pix[1])) # perturb the pixel. | ||
dx = abs(ptp[0] - where) | ||
|
||
return dx | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here and below, PEP8 spaces after commas, please.