I have two curves defined by two sets of arrays: (x1, y1)
and (x2, y2)
and I want to fill between them with polygons. All arrays are the same length but x1
and x2
contain different values.
plt.fill_between(x, y1, y2)
requires that both curves share the same x-array.
How do I do something like fill_between(x1, y1, x2, y2)
?
For instance if:
x1 = np.array([1.0, 2.0, 3.0, 4.0, 5.0])
and y1 = np.array([3.0, 2.0, 3.0, 2.0, 3.0])
define the first curve
and
x2 = np.array([1.5, 2.5 ,3.5 ,4.5 , 5.5])
and y2 = np.array([5.0, 6.0, 7.0, 8.0, 9.0])
define the second.
How can I fill colour between curves (x1, y1)
and (x2, y2)
using four polygons (the left and right boundaries need not be vertical)?
To clarify, the four polygons (A,B,C,D) would have coordinates:
A: [(1.0, 3.0), (1.5, 5.0), (2.5, 6.0), (2.0, 2.0)]
B: [(2.0, 2.0), (2.5, 6.0), (3.5, 7.0), (3.0, 3.0)]
C: [(3.0, 3.0), (3.5, 7.0), (4.5, 8.0), (4.0, 2.0)]
D: [(4.0, 2.0), (4.5, 8.0), (5.5, 9.0), (5.0, 3.0)]