Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3f38eaf

Browse filesBrowse files
committed
added interpolate functionaly to fill_betweenx, as in fill_between, enabled through keyword argument interpolate.
1 parent cb01731 commit 3f38eaf
Copy full SHA for 3f38eaf

File tree

Expand file treeCollapse file tree

2 files changed

+44
-7
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+44
-7
lines changed
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Interpolation in fill_betweenx
2+
------------------------------
3+
4+
The ``interpolate`` parameter now exists for the method :func:`fill_betweenx`.
5+
This allows a user to interpolate the data and fill the areas in the crossover
6+
points, similarly to :func:`fill_between`.

‎lib/matplotlib/axes/_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_axes.py
+38-7Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4847,13 +4847,14 @@ def get_interp_point(ind):
48474847
label_namer=None)
48484848
@docstring.dedent_interpd
48494849
def fill_betweenx(self, y, x1, x2=0, where=None,
4850-
step=None, **kwargs):
4850+
step=None, interpolate=False, **kwargs):
48514851
"""
48524852
Make filled polygons between two horizontal curves.
48534853
48544854
Call signature::
48554855
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)
48574858
48584859
Create a :class:`~matplotlib.collections.PolyCollection`
48594860
filling the regions between *x1* and *x2* where
@@ -4878,6 +4879,12 @@ def fill_betweenx(self, y, x1, x2=0, where=None,
48784879
step : {'pre', 'post', 'mid'}, optional
48794880
If not None, fill with step logic.
48804881
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+
48814888
Notes
48824889
-----
48834890
@@ -4940,12 +4947,36 @@ def fill_betweenx(self, y, x1, x2=0, where=None,
49404947

49414948
N = len(yslice)
49424949
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]
49434977

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
49494980

49504981
Y[1:N + 1, 0] = x1slice
49514982
Y[1:N + 1, 1] = yslice

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.