@@ -98,36 +98,28 @@ The following graph illustrates the firm's constraints and iso-revenue lines.
9898tags: [hide-input]
9999---
100100fig, ax = plt.subplots()
101- ax.grid()
102-
103101# Draw constraint lines
104- ax.hlines(0, -1, 17.5)
105- ax.vlines(0, -1, 12)
106- ax.plot(np.linspace(-1, 17.5, 100), 6-0.4*np.linspace(-1, 17.5, 100), color="r")
107- ax.plot(np.linspace(-1, 5.5, 100), 10-2*np.linspace(-1, 5.5, 100), color="r")
108- ax.text(1.5, 8, "$2x_1 + 5x_2 \leq 30$", size=12)
109- ax.text(10, 2.5, "$4x_1 + 2x_2 \leq 20$", size=12)
110- ax.text(-2, 2, "$x_2 \geq 0$", size=12)
111- ax.text(2.5, -0.7, "$x_1 \geq 0$", size=12)
102+ ax.set_xlim(0,15)
103+ ax.set_ylim(0,10)
104+ x1 = np.linspace(0, 15)
105+ ax.plot(x1, 6-0.4*x1, label="$2x_1 + 5x_2=30$")
106+ ax.plot(x1, 10-2*x1, label="$4x_1 + 2x_2=20$")
107+
112108
113109# Draw the feasible region
114- feasible_set = Polygon(np.array([[0, 0],
115- [0, 6],
116- [2.5, 5],
117- [5, 0]]),
118- color="cyan")
110+ feasible_set = Polygon(np.array([[0, 0],[0, 6],[2.5, 5],[5, 0]]), alpha=0.1)
119111ax.add_patch(feasible_set)
120112
121113# Draw the objective function
122- ax.plot(np.linspace(-1, 5.5, 100), 3.875-0.75*np.linspace(-1, 5.5, 100), color="orange")
123- ax.plot(np.linspace(-1, 5.5, 100), 5.375-0.75*np.linspace(-1, 5.5, 100), color="orange")
124- ax.plot(np.linspace(-1, 5.5, 100), 6.875-0.75*np.linspace(-1, 5.5, 100), color="orange")
125- ax.arrow(-1.6, 5, 0, 2, width = 0.05, head_width=0.2, head_length=0.5, color="orange")
126- ax.text(5.7, 1, "$z = 3x_1 + 4x_2$", size=12)
114+ ax.plot(x1, 3.875-0.75*x1, label="iso-revenue lines",color='k',linewidth=0.75)
115+ ax.plot(x1, 5.375-0.75*x1, color='k',linewidth=0.75)
116+ ax.plot(x1, 6.875-0.75*x1, color='k',linewidth=0.75)
127117
128118# Draw the optimal solution
129- ax.plot(2.5, 5, "*", color="black")
130- ax.text(2.7, 5.2, "Optimal Solution", size=12)
119+ ax.plot(2.5, 5, ".", label="optimal solution")
120+ ax.set_xlabel("$x_1$")
121+ ax.set_ylabel("$x_2$")
122+ ax.legend()
131123
132124plt.show()
133125```
0 commit comments