@@ -972,11 +972,24 @@ def _update_ticks(self, renderer):
972
972
tick_tups = [ti for ti in tick_tups
973
973
if (ti [1 ] >= ilow ) and (ti [1 ] <= ihigh )]
974
974
975
+ # so that we don't lose ticks on the end, expand out the interval ever so slightly. The
976
+ # "ever so slightly" is defined to be the width of a half of a pixel. We don't want to draw
977
+ # a tick that even one pixel outside of the defined axis interval.
978
+ if interval [0 ] <= interval [1 ]:
979
+ interval_expanded = interval
980
+ else :
981
+ interval_expanded = interval [1 ],interval [0 ]
982
+
983
+ if hasattr (self ,'_get_pixel_distance_along_axis' ):
984
+ ds1 = self ._get_pixel_distance_along_axis (interval_expanded [0 ],- 1 )/ 2.0
985
+ ds2 = self ._get_pixel_distance_along_axis (interval_expanded [1 ],+ 1 )/ 2.0
986
+ interval_expanded = (interval [0 ]- ds1 ,interval [1 ]+ ds2 )
987
+
975
988
ticks_to_draw = []
976
989
for tick , loc , label in tick_tups :
977
990
if tick is None :
978
991
continue
979
- if not mtransforms .interval_contains (interval , loc ):
992
+ if not mtransforms .interval_contains (interval_expanded , loc ):
980
993
continue
981
994
tick .update_position (loc )
982
995
tick .set_label1 (label )
@@ -1599,6 +1612,24 @@ def _get_offset_text(self):
1599
1612
self .offset_text_position = 'bottom'
1600
1613
return offsetText
1601
1614
1615
+ def _get_pixel_distance_along_axis (self ,where ,perturb ):
1616
+ # returns the amount, in data coordinates, that a single pixel corresponds to in the
1617
+ # locality given by "where", which is also given in data coordinates, and is an x coordinate.
1618
+ # "perturb" is the amount to perturb the pixel. Usually +1 or -1.
1619
+
1620
+ # first figure out the pixel location of the "where" point. We use 1e-10 for the
1621
+ # y point, so that we remain compatible with log axes.
1622
+ #
1623
+ # I THINK this will work too for polar axes, but I'm not 100% sure.
1624
+ #
1625
+ trans = self .axes .transData # transformation from data coords to display coords
1626
+ transinv = trans .inverted () # transformation from display coords to data coords
1627
+ pix = trans .transform_point ((where ,1e-10 ))
1628
+ ptp = transinv .transform_point ((pix [0 ]+ perturb ,pix [1 ])) # perturb the pixel.
1629
+ dx = abs (ptp [0 ]- where )
1630
+
1631
+ return dx
1632
+
1602
1633
def get_label_position (self ):
1603
1634
"""
1604
1635
Return the label position (top or bottom)
@@ -1874,6 +1905,22 @@ def _get_offset_text(self):
1874
1905
self .offset_text_position = 'left'
1875
1906
return offsetText
1876
1907
1908
+ def _get_pixel_distance_along_axis (self ,where ,perturb ):
1909
+ # returns the amount, in data coordinates, that a single pixel corresponds to in the
1910
+ # locality given by "where", which is also given in data coordinates, and is a y coordinate.
1911
+ # "perturb" is the amount to perturb the pixel. Usually +1 or -1.
1912
+
1913
+ # first figure out the pixel location of the "where" point. We use 1e-10 for the
1914
+ # x point, so that we remain compatible with log axes.
1915
+ #
1916
+ # I THINK this will work too for polar axes, but I'm not 100% sure.
1917
+ #
1918
+ trans = self .axes .transData # transformation from data coords to display coords
1919
+ transinv = trans .inverted () # transformation from display coords to data coords
1920
+ pix = trans .transform_point ((1e-10 ,where ))
1921
+ ptp = transinv .transform_point ((pix [0 ],pix [1 ]+ perturb )) # perturb the pixel.
1922
+ dy = abs (ptp [1 ]- where )
1923
+
1877
1924
def get_label_position (self ):
1878
1925
"""
1879
1926
Return the label position (left or right)
0 commit comments