@@ -4896,13 +4896,14 @@ def get_interp_point(ind):
48964896 label_namer = None )
48974897 @docstring .dedent_interpd
48984898 def fill_betweenx (self , y , x1 , x2 = 0 , where = None ,
4899- step = None , ** kwargs ):
4899+ step = None , interpolate = False , ** kwargs ):
49004900 """
49014901 Make filled polygons between two horizontal curves.
49024902
49034903 Call signature::
49044904
4905- fill_betweenx(y, x1, x2=0, where=None, **kwargs)
4905+ fill_betweenx(y, x1, x2=0, where=None, step=None,
4906+ interpolate=False, **kwargs)
49064907
49074908 Create a :class:`~matplotlib.collections.PolyCollection`
49084909 filling the regions between *x1* and *x2* where
@@ -4927,6 +4928,12 @@ def fill_betweenx(self, y, x1, x2=0, where=None,
49274928 step : {'pre', 'post', 'mid'}, optional
49284929 If not None, fill with step logic.
49294930
4931+ interpolate : bool, optional
4932+ If `True`, interpolate between the two lines to find the
4933+ precise point of intersection. Otherwise, the start and
4934+ end points of the filled region will only occur on explicit
4935+ values in the *x* array.
4936+
49304937 Notes
49314938 -----
49324939
@@ -4995,13 +5002,37 @@ def fill_betweenx(self, y, x1, x2=0, where=None,
49955002 continue
49965003
49975004 N = len (yslice )
4998- Y = np .zeros ((2 * N + 2 , 2 ), float )
5005+ Y = np .zeros ((2 * N + 2 , 2 ), np .float )
5006+ if interpolate :
5007+ def get_interp_point (ind ):
5008+ im1 = max (ind - 1 , 0 )
5009+ y_values = y [im1 :ind + 1 ]
5010+ diff_values = x1 [im1 :ind + 1 ] - x2 [im1 :ind + 1 ]
5011+ x1_values = x1 [im1 :ind + 1 ]
5012+
5013+ if len (diff_values ) == 2 :
5014+ if np .ma .is_masked (diff_values [1 ]):
5015+ return x1 [im1 ], y [im1 ]
5016+ elif np .ma .is_masked (diff_values [0 ]):
5017+ return x1 [ind ], y [ind ]
5018+
5019+ diff_order = diff_values .argsort ()
5020+ diff_root_y = np .interp (
5021+ 0 , diff_values [diff_order ], y_values [diff_order ])
5022+ diff_root_x = np .interp (diff_root_y , y_values , x1_values )
5023+ return diff_root_x , diff_root_y
5024+
5025+ start = get_interp_point (ind0 )
5026+ end = get_interp_point (ind1 )
5027+ else :
5028+ # the purpose of the next two lines is for when x2 is a
5029+ # scalar like 0 and we want the fill to go all the way
5030+ # down to 0 even if none of the x1 sample points do
5031+ start = x2slice [0 ], yslice [0 ]
5032+ end = x2slice [- 1 ], yslice [- 1 ]
49995033
5000- # the purpose of the next two lines is for when x2 is a
5001- # scalar like 0 and we want the fill to go all the way
5002- # down to 0 even if none of the x1 sample points do
5003- Y [0 ] = x2slice [0 ], yslice [0 ]
5004- Y [N + 1 ] = x2slice [- 1 ], yslice [- 1 ]
5034+ Y [0 ] = start
5035+ Y [N + 1 ] = end
50055036
50065037 Y [1 :N + 1 , 0 ] = x1slice
50075038 Y [1 :N + 1 , 1 ] = yslice
0 commit comments