@@ -4810,13 +4810,14 @@ def get_interp_point(ind):
4810
4810
label_namer = None )
4811
4811
@docstring .dedent_interpd
4812
4812
def fill_betweenx (self , y , x1 , x2 = 0 , where = None ,
4813
- step = None , ** kwargs ):
4813
+ step = None , interpolate = False , ** kwargs ):
4814
4814
"""
4815
4815
Make filled polygons between two horizontal curves.
4816
4816
4817
4817
Call signature::
4818
4818
4819
- fill_betweenx(y, x1, x2=0, where=None, **kwargs)
4819
+ fill_betweenx(y, x1, x2=0, where=None, step=None,
4820
+ interpolate=False, **kwargs)
4820
4821
4821
4822
Create a :class:`~matplotlib.collections.PolyCollection`
4822
4823
filling the regions between *x1* and *x2* where
@@ -4841,6 +4842,12 @@ def fill_betweenx(self, y, x1, x2=0, where=None,
4841
4842
step : {'pre', 'post', 'mid'}, optional
4842
4843
If not None, fill with step logic.
4843
4844
4845
+ interpolate : bool, optional
4846
+ If `True`, interpolate between the two lines to find the
4847
+ precise point of intersection. Otherwise, the start and
4848
+ end points of the filled region will only occur on explicit
4849
+ values in the *x* array.
4850
+
4844
4851
Notes
4845
4852
-----
4846
4853
@@ -4902,13 +4909,37 @@ def fill_betweenx(self, y, x1, x2=0, where=None,
4902
4909
continue
4903
4910
4904
4911
N = len (yslice )
4905
- Y = np .zeros ((2 * N + 2 , 2 ), float )
4912
+ Y = np .zeros ((2 * N + 2 , 2 ), np .float )
4913
+ if interpolate :
4914
+ def get_interp_point (ind ):
4915
+ im1 = max (ind - 1 , 0 )
4916
+ y_values = y [im1 :ind + 1 ]
4917
+ diff_values = x1 [im1 :ind + 1 ] - x2 [im1 :ind + 1 ]
4918
+ x1_values = x1 [im1 :ind + 1 ]
4919
+
4920
+ if len (diff_values ) == 2 :
4921
+ if np .ma .is_masked (diff_values [1 ]):
4922
+ return x1 [im1 ], y [im1 ]
4923
+ elif np .ma .is_masked (diff_values [0 ]):
4924
+ return x1 [ind ], y [ind ]
4925
+
4926
+ diff_order = diff_values .argsort ()
4927
+ diff_root_y = np .interp (
4928
+ 0 , diff_values [diff_order ], y_values [diff_order ])
4929
+ diff_root_x = np .interp (diff_root_y , y_values , x1_values )
4930
+ return diff_root_x , diff_root_y
4931
+
4932
+ start = get_interp_point (ind0 )
4933
+ end = get_interp_point (ind1 )
4934
+ else :
4935
+ # the purpose of the next two lines is for when x2 is a
4936
+ # scalar like 0 and we want the fill to go all the way
4937
+ # down to 0 even if none of the x1 sample points do
4938
+ start = x2slice [0 ], yslice [0 ]
4939
+ end = x2slice [- 1 ], yslice [- 1 ]
4906
4940
4907
- # the purpose of the next two lines is for when x2 is a
4908
- # scalar like 0 and we want the fill to go all the way
4909
- # down to 0 even if none of the x1 sample points do
4910
- Y [0 ] = x2slice [0 ], yslice [0 ]
4911
- Y [N + 1 ] = x2slice [- 1 ], yslice [- 1 ]
4941
+ Y [0 ] = start
4942
+ Y [N + 1 ] = end
4912
4943
4913
4944
Y [1 :N + 1 , 0 ] = x1slice
4914
4945
Y [1 :N + 1 , 1 ] = yslice
0 commit comments