用matplotlib应用一下线性规划
import numpy as np import matplotlib.pyplot as plt x1=np.linspace(0,5,200) fig,ax=plt.subplots() ax.plot(x1,-3/5*x1+3,label='3*x1+5*x2=15') ax.plot(x1,-3*x1+12,label='6*x1+2*x2=24') ax.plot([0,2,4,6],[0,0,0,0],label='x2=0') ax.plot([0,0,0,0],[0,4,8,12],label='x1=0') y1=-3/5*x1+3 y2=-3*x1+12 y3=np.minimum(y1,y2) plt.fill_between(x1,0,y3,where=y3>0,color='gray') ax.set_xlim(0,8) ax.set_ylim(0,12) ax.set_xlabel('x1 label') ax.set_ylabel('x2 label') ax.legend() plt.show()