@@ -4847,13 +4847,14 @@ def get_interp_point(ind):
4847
4847
label_namer = None )
4848
4848
@docstring .dedent_interpd
4849
4849
def fill_betweenx (self , y , x1 , x2 = 0 , where = None ,
4850
- step = None , ** kwargs ):
4850
+ step = None , interpolate = False , ** kwargs ):
4851
4851
"""
4852
4852
Make filled polygons between two horizontal curves.
4853
4853
4854
4854
Call signature::
4855
4855
4856
- fill_betweenx(y, x1, x2=0, where=None, **kwargs)
4856
+ fill_betweenx(y, x1, x2=0, where=None, step=None,
4857
+ interpolate=False, **kwargs)
4857
4858
4858
4859
Create a :class:`~matplotlib.collections.PolyCollection`
4859
4860
filling the regions between *x1* and *x2* where
@@ -4878,6 +4879,12 @@ def fill_betweenx(self, y, x1, x2=0, where=None,
4878
4879
step : {'pre', 'post', 'mid'}, optional
4879
4880
If not None, fill with step logic.
4880
4881
4882
+ interpolate : bool, optional
4883
+ If `True`, interpolate between the two lines to find the
4884
+ precise point of intersection. Otherwise, the start and
4885
+ end points of the filled region will only occur on explicit
4886
+ values in the *x* array.
4887
+
4881
4888
Notes
4882
4889
-----
4883
4890
@@ -4940,12 +4947,36 @@ def fill_betweenx(self, y, x1, x2=0, where=None,
4940
4947
4941
4948
N = len (yslice )
4942
4949
Y = np .zeros ((2 * N + 2 , 2 ), np .float )
4950
+ if interpolate :
4951
+ def get_interp_point (ind ):
4952
+ im1 = max (ind - 1 , 0 )
4953
+ y_values = y [im1 :ind + 1 ]
4954
+ diff_values = x1 [im1 :ind + 1 ] - x2 [im1 :ind + 1 ]
4955
+ x1_values = x1 [im1 :ind + 1 ]
4956
+
4957
+ if len (diff_values ) == 2 :
4958
+ if np .ma .is_masked (diff_values [1 ]):
4959
+ return x1 [im1 ], y [im1 ]
4960
+ elif np .ma .is_masked (diff_values [0 ]):
4961
+ return x1 [ind ], y [ind ]
4962
+
4963
+ diff_order = diff_values .argsort ()
4964
+ diff_root_y = np .interp (
4965
+ 0 , diff_values [diff_order ], y_values [diff_order ])
4966
+ diff_root_x = np .interp (diff_root_y , y_values , x1_values )
4967
+ return diff_root_x , diff_root_y
4968
+
4969
+ start = get_interp_point (ind0 )
4970
+ end = get_interp_point (ind1 )
4971
+ else :
4972
+ # the purpose of the next two lines is for when x2 is a
4973
+ # scalar like 0 and we want the fill to go all the way
4974
+ # down to 0 even if none of the x1 sample points do
4975
+ start = x2slice [0 ], yslice [0 ]
4976
+ end = x2slice [- 1 ], yslice [- 1 ]
4943
4977
4944
- # the purpose of the next two lines is for when x2 is a
4945
- # scalar like 0 and we want the fill to go all the way
4946
- # down to 0 even if none of the x1 sample points do
4947
- Y [0 ] = x2slice [0 ], yslice [0 ]
4948
- Y [N + 1 ] = x2slice [- 1 ], yslice [- 1 ]
4978
+ Y [0 ] = start
4979
+ Y [N + 1 ] = end
4949
4980
4950
4981
Y [1 :N + 1 , 0 ] = x1slice
4951
4982
Y [1 :N + 1 , 1 ] = yslice
0 commit comments