@@ -783,6 +783,7 @@ def axhline(self, y=0, xmin=0, xmax=1, **kwargs):
783783 trans = self .get_yaxis_transform (which = 'grid' )
784784 l = mlines .Line2D ([xmin , xmax ], [y , y ], transform = trans , ** kwargs )
785785 self .add_line (l )
786+ l .get_path ()._interpolation_steps = mpl .axis .GRIDLINE_INTERPOLATION_STEPS
786787 if scaley :
787788 self ._request_autoscale_view ("y" )
788789 return l
@@ -851,6 +852,7 @@ def axvline(self, x=0, ymin=0, ymax=1, **kwargs):
851852 trans = self .get_xaxis_transform (which = 'grid' )
852853 l = mlines .Line2D ([x , x ], [ymin , ymax ], transform = trans , ** kwargs )
853854 self .add_line (l )
855+ l .get_path ()._interpolation_steps = mpl .axis .GRIDLINE_INTERPOLATION_STEPS
854856 if scalex :
855857 self ._request_autoscale_view ("x" )
856858 return l
@@ -978,10 +980,17 @@ def axhspan(self, ymin, ymax, xmin=0, xmax=1, **kwargs):
978980 self ._check_no_units ([xmin , xmax ], ['xmin' , 'xmax' ])
979981 (ymin , ymax ), = self ._process_unit_info ([("y" , [ymin , ymax ])], kwargs )
980982
981- verts = (xmin , ymin ), (xmin , ymax ), (xmax , ymax ), (xmax , ymin )
982- p = mpatches .Polygon (verts , ** kwargs )
983+ p = mpatches .Rectangle ((xmin , ymin ), xmax - xmin , ymax - ymin , ** kwargs )
983984 p .set_transform (self .get_yaxis_transform (which = "grid" ))
985+ # For Rectangles and non-separable transforms, add_patch can be buggy
986+ # and update the x limits even though it shouldn't do so for an
987+ # yaxis_transformed patch, so undo that update.
988+ ix = self .dataLim .intervalx
989+ mx = self .dataLim .minposx
984990 self .add_patch (p )
991+ self .dataLim .intervalx = ix
992+ self .dataLim .minposx = mx
993+ p .get_path ()._interpolation_steps = mpl .axis .GRIDLINE_INTERPOLATION_STEPS
985994 self ._request_autoscale_view ("y" )
986995 return p
987996
@@ -1034,11 +1043,17 @@ def axvspan(self, xmin, xmax, ymin=0, ymax=1, **kwargs):
10341043 self ._check_no_units ([ymin , ymax ], ['ymin' , 'ymax' ])
10351044 (xmin , xmax ), = self ._process_unit_info ([("x" , [xmin , xmax ])], kwargs )
10361045
1037- verts = [(xmin , ymin ), (xmin , ymax ), (xmax , ymax ), (xmax , ymin )]
1038- p = mpatches .Polygon (verts , ** kwargs )
1046+ p = mpatches .Rectangle ((xmin , ymin ), xmax - xmin , ymax - ymin , ** kwargs )
10391047 p .set_transform (self .get_xaxis_transform (which = "grid" ))
1040- p .get_path ()._interpolation_steps = 100
1048+ # For Rectangles and non-separable transforms, add_patch can be buggy
1049+ # and update the y limits even though it shouldn't do so for an
1050+ # xaxis_transformed patch, so undo that update.
1051+ iy = self .dataLim .intervaly .copy ()
1052+ my = self .dataLim .minposy
10411053 self .add_patch (p )
1054+ self .dataLim .intervaly = iy
1055+ self .dataLim .minposy = my
1056+ p .get_path ()._interpolation_steps = mpl .axis .GRIDLINE_INTERPOLATION_STEPS
10421057 self ._request_autoscale_view ("x" )
10431058 return p
10441059
0 commit comments