f3 = lambda t, x: x * (x - t)
fig, ax = plt.subplots(figsize=(7, 5))
slope_field(f3, (-1, 4), (-3, 4.5), n=22, ax=ax)
t_eval = np.linspace(-1, 4, 600)
for x0, t0 in [(2.0, -1), (0.5, -1), (-1.5, -1), (3.5, -1)]:
try:
sol = solve_ivp(f3, (-1, 4), [x0], t_eval=t_eval, max_step=0.02,
events=lambda t, y: y[0] - 15)
ax.plot(sol.t, np.clip(sol.y[0], -4, 5), color='steelblue', lw=1.8)
except Exception:
pass
t_nc = np.linspace(-1, 4, 200)
ax.axhline(0, color='crimson', linestyle='--', lw=1.8, label='Nullcline $x=0$')
ax.plot(t_nc, t_nc, color='darkorange', linestyle='--', lw=1.8, label='Nullcline $x=t$')
# Sign annotations
for txt, pos in [(r"$x'>0$", (2, -1.8)), (r"$x'<0$", (2, 0.6)),
(r"$x'>0$", (0.5, 2.5)), (r"$x'<0$", (-0.5, -1.5))]:
ax.text(*pos, txt, fontsize=10, ha='center', color='black')
ax.set_xlim(-1, 4); ax.set_ylim(-3, 4.5)
ax.set_title(r"Slope field: $x' = x(x-t)$")
ax.legend(fontsize=9)
plt.tight_layout()
plt.show()