@@ -4896,13 +4896,14 @@ def get_interp_point(ind):
4896
4896
label_namer = None )
4897
4897
@docstring .dedent_interpd
4898
4898
def fill_betweenx (self , y , x1 , x2 = 0 , where = None ,
4899
- step = None , ** kwargs ):
4899
+ step = None , interpolate = False , ** kwargs ):
4900
4900
"""
4901
4901
Make filled polygons between two horizontal curves.
4902
4902
4903
4903
Call signature::
4904
4904
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)
4906
4907
4907
4908
Create a :class:`~matplotlib.collections.PolyCollection`
4908
4909
filling the regions between *x1* and *x2* where
@@ -4927,6 +4928,12 @@ def fill_betweenx(self, y, x1, x2=0, where=None,
4927
4928
step : {'pre', 'post', 'mid'}, optional
4928
4929
If not None, fill with step logic.
4929
4930
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
+
4930
4937
Notes
4931
4938
-----
4932
4939
@@ -4995,13 +5002,37 @@ def fill_betweenx(self, y, x1, x2=0, where=None,
4995
5002
continue
4996
5003
4997
5004
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 ]
4999
5033
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
5005
5036
5006
5037
Y [1 :N + 1 , 0 ] = x1slice
5007
5038
Y [1 :N + 1 , 1 ] = yslice
0 commit comments