我用matplotlib绘制了线性不等式。如何沿线打印方程式?我不想在每行的右边加上标签。
这是我目前的代码:
import numpy as np
import matplotlib.pyplot as plt
# Construct lines
# x > 0
x = np.linspace(0, 20, 2000)
# x1 >= 0
y1 = (x*0) + 0
# 2x1+x2<=10
y2 = 10-2*x
# x2 >= 4x-8
y3 = (4*x-8)/4.0
# y <= 2x - 5
y4 = (5 * x +2)/2
plt.xlabel(r'$x_2>=0$')
plt.ylabel(r'$x_1>=0$')
# Make plot
plt.plot(x, y1)
plt.plot(x, y2)
plt.plot(x, y3)
plt.plot(x, y4)
plt.xlim((0, 16))
plt.ylim((0, 11))
# Fill feasible region
y5 = np.minimum(y2, y4)
y6 = np.maximum(y1, y3)
plt.fill_between(x, y5, y6, where=y5>y6, color='grey', alpha=0.5)
plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
plt.grid()
plt.show()