1

I need to fill the area between y1 and y but but I don't understand how to limit the area under y2

import numpy as np
import matplotlib.pyplot as plt

y = lambda z: (4 * z - z ** 2) ** (1 / 2)
y1 = lambda x: (8 * x - x ** 2) ** (1 / 2)
y2 = lambda c: c * 3 ** (1 / 2)
x = np.linspace(0, 12, 500)
z = np.linspace(0, 12, 500)
c = np.linspace(0, 12, 500)
plt.ylim(0, 4)
plt.xlim(0, 4)

plt.plot(z, y(z), color='blue', label="$y=\\sqrt{4x-x^2}$")
plt.plot(c, y2(c), color='black', label='$y=x\\sqrt{3}$')
plt.plot(x, y1(x), color='red', label='$y=\\sqrt{8x-x^2}$')
plt.plot([0, 4], [0, 0], color='yellow', label='y=0')
plt.grid(True, zorder=5)

plt.fill_between(x, y(z), y1(x), where=(y2(c) >= y1(x)), alpha=0.5)
plt.legend()
plt.show()
anonim
  • 67
  • 5
  • Isn't this about the same as your [previous question](https://stackoverflow.com/questions/60782232/how-to-fill-space-to-border-with-in-matplotlib)? – JohanC Mar 21 '20 at 20:59
  • Yes,i still can't understand how to use method fill_between. – anonim Mar 23 '20 at 18:35

1 Answers1

2

Do you want to fill between the minimum of y1, y2 and y?

miny = np.minimum(y2(x),y1(x))
plt.fill_between(x, y(x), miny, where=(miny>=y(x)), alpha=0.5)

plt.legend()
plt.show()

Output:

enter image description here

Quang Hoang
  • 146,074
  • 10
  • 56
  • 74