Martin Bouhier
Martin Bouhier

Reputation: 173

Fill area between two lines with Python

I am looking for fill the area between two lines in matplot. Any way to do this?

a = [[12, 17, 26, 32, 34], [235.910888671875, 245.84429931640625, 211.8711395263672, 226.2964630126953, 222.0032501220703]]
b = [[12, 26, 34], [235.910888671875, 211.8711395263672, 222.0032501220703]]

plt.plot(a[0], a[1], c='r')
plt.plot(b[0], b[1], c='r')

enter image description here

Upvotes: 3

Views: 526

Answers (1)

razimbres
razimbres

Reputation: 5015

Here it is:

import matplotlib.pyplot as plt
import numpy as np
a = [[12, 17, 26, 32, 34], [235.910888671875, 245.84429931640625, 211.8711395263672, 226.2964630126953, 222.0032501220703]]
b = [[12, 26, 34], [235.910888671875, 211.8711395263672, 222.0032501220703]]

plt.plot(a[0], a[1], c='r')
plt.plot(b[0], b[1], c='r')
plt.fill_between(a[0], a[1],np.min(a[1]))
plt.fill_between(b[0], b[1],np.min(a[1]),color='white')
plt.show()

Pic

Upvotes: 2

Related Questions