Using Fill_between And Min/max To Represent Inequalities
My code: import matplotlib.pyplot as plt import numpy as np # x > 0 x = np.linspace(0,17, 100) #x2>=0 y0 = (x*0) #-x1+x2 <= 1 y1 = 1+x #x1+6x2 <= 15 y2 = 15/6 - (1/6)*
Solution 1:
You can use np.maxiumum
and np.minimum
to define your y-values. This way you don't have to "piece-wise" it. Use maximum
on your lower bounds to define just one lower bound to plot. Same with minimum
and your upper bounds. Also, in your example, you cut off the y axis, where you there is actually shaded area below.
Y1 = np.maximum(y0, y3)
Y2 = np.minimum(y1, y2)
plt.fill_between(x, Y1, Y2, where = Y1 < Y2, color = 'grey', alpha = 0.5)
Post a Comment for "Using Fill_between And Min/max To Represent Inequalities"