@@ -4853,10 +4853,15 @@ def get_interp_point(ind):
4853
4853
label_namer = None )
4854
4854
@docstring .dedent_interpd
4855
4855
def fill_betweenx (self , y , x1 , x2 = 0 , where = None ,
4856
- step = None , ** kwargs ):
4856
+ step = None , interpolate = False , ** kwargs ):
4857
4857
"""
4858
4858
Make filled polygons between two horizontal curves.
4859
4859
4860
+ Call signature::
4861
+
4862
+ fill_betweenx(y, x1, x2=0, where=None, step=None,
4863
+ interpolate=False, **kwargs)
4864
+
4860
4865
Create a :class:`~matplotlib.collections.PolyCollection`
4861
4866
filling the regions between *x1* and *x2* where
4862
4867
``where==True``
@@ -4880,6 +4885,12 @@ def fill_betweenx(self, y, x1, x2=0, where=None,
4880
4885
step : {'pre', 'post', 'mid'}, optional
4881
4886
If not None, fill with step logic.
4882
4887
4888
+ interpolate : bool, optional
4889
+ If `True`, interpolate between the two lines to find the
4890
+ precise point of intersection. Otherwise, the start and
4891
+ end points of the filled region will only occur on explicit
4892
+ values in the *x* array.
4893
+
4883
4894
Notes
4884
4895
-----
4885
4896
@@ -4948,13 +4959,37 @@ def fill_betweenx(self, y, x1, x2=0, where=None,
4948
4959
continue
4949
4960
4950
4961
N = len (yslice )
4951
- Y = np .zeros ((2 * N + 2 , 2 ), float )
4962
+ Y = np .zeros ((2 * N + 2 , 2 ), np .float )
4963
+ if interpolate :
4964
+ def get_interp_point (ind ):
4965
+ im1 = max (ind - 1 , 0 )
4966
+ y_values = y [im1 :ind + 1 ]
4967
+ diff_values = x1 [im1 :ind + 1 ] - x2 [im1 :ind + 1 ]
4968
+ x1_values = x1 [im1 :ind + 1 ]
4969
+
4970
+ if len (diff_values ) == 2 :
4971
+ if np .ma .is_masked (diff_values [1 ]):
4972
+ return x1 [im1 ], y [im1 ]
4973
+ elif np .ma .is_masked (diff_values [0 ]):
4974
+ return x1 [ind ], y [ind ]
4975
+
4976
+ diff_order = diff_values .argsort ()
4977
+ diff_root_y = np .interp (
4978
+ 0 , diff_values [diff_order ], y_values [diff_order ])
4979
+ diff_root_x = np .interp (diff_root_y , y_values , x1_values )
4980
+ return diff_root_x , diff_root_y
4981
+
4982
+ start = get_interp_point (ind0 )
4983
+ end = get_interp_point (ind1 )
4984
+ else :
4985
+ # the purpose of the next two lines is for when x2 is a
4986
+ # scalar like 0 and we want the fill to go all the way
4987
+ # down to 0 even if none of the x1 sample po
8427
ints do
4988
+ start = x2slice [0 ], yslice [0 ]
4989
+ end = x2slice [- 1 ], yslice [- 1 ]
4952
4990
4953
- # the purpose of the next two lines is for when x2 is a
4954
- # scalar like 0 and we want the fill to go all the way
4955
- # down to 0 even if none of the x1 sample points do
4956
- Y [0 ] = x2slice [0 ], yslice [0 ]
4957
- Y [N + 1 ] = x2slice [- 1 ], yslice [- 1 ]
4991
+ Y [0 ] = start
4992
+ Y [N + 1 ] = end
4958
4993
4959
4994
Y [1 :N + 1 , 0 ] = x1slice
4960
4995
Y [1 :N + 1 , 1 ] = yslice
0 commit comments