import matplotlib.pyplot as plt
import numpy as np
def arrow(ax, start, vec, color, label, at=0.5, shift=(0.1, 0.1)):
ax.quiver(*start, *vec, angles="xy", scale_units="xy", scale=1, color=color, width=0.012)
pos = np.asarray(start) + np.asarray(vec) * at
ax.text(pos[0] + shift[0], pos[1] + shift[1], label, color=color, fontsize=13)
v, w = np.array([2.0, 1.0]), np.array([1.0, 2.0])
fig, axes = plt.subplots(1, 2, figsize=(8, 3.4))
arrow(axes[0], (0, 0), v, "tab:blue", r"$\mathbf{v}$", shift=(0.1, -0.4))
arrow(axes[0], v, w, "tab:orange", r"$\mathbf{w}$", shift=(0.3, -0.25))
arrow(axes[0], (0, 0), v + w, "tab:green", r"$\mathbf{v}+\mathbf{w}$", shift=(-1.0, 0.25))
arrow(axes[1], (0, 0), 2 * v, "tab:red", r"$2\mathbf{v}$", at=0.8, shift=(0.0, -0.55))
arrow(axes[1], (0, 0), v, "tab:blue", r"$\mathbf{v}$", shift=(-0.25, 0.25))
arrow(axes[1], (0, 0), -v, "tab:purple", r"$-\mathbf{v}$", shift=(-0.3, 0.25))
for ax in axes:
ax.set_xlim(-2.5, 4.5)
ax.set_ylim(-1.5, 3.5)
ax.set_aspect("equal")
ax.grid(alpha=0.3)
ax.axhline(0, color="gray", lw=0.8)
ax.axvline(0, color="gray", lw=0.8)
plt.tight_layout()
plt.show()