Plot.plot({
style: "overflow: visible; display: block; margin: 0 auto;",
width: 600,
height: 500,
grid: true,
x: {label: "x_1", domain: [-12, 12]},
y: {label: "x_2", domain: [-12, 12]},
marks: [
Plot.ruleY([0], {stroke: "#ddd"}),
Plot.ruleX([0], {stroke: "#ddd"}),
// Vector u (blue)
Plot.arrow([{x1: 0, y1: 0, x2: u1_sub, y2: u2_sub}], {
x1: "x1", y1: "y1", x2: "x2", y2: "y2",
stroke: "steelblue", strokeWidth: 3, fill: "steelblue"
}),
// Vector v (red)
Plot.arrow([{x1: 0, y1: 0, x2: v1_sub, y2: v2_sub}], {
x1: "x1", y1: "y1", x2: "x2", y2: "y2",
stroke: "crimson", strokeWidth: 3, fill: "crimson"
}),
// Vector -v (red dashed)
Plot.arrow([{x1: 0, y1: 0, x2: -v1_sub, y2: -v2_sub}], {
x1: "x1", y1: "y1", x2: "x2", y2: "y2",
stroke: "crimson", strokeWidth: 2, fill: "crimson",
strokeDasharray: "5,5", fillOpacity: 0.6
}),
// Vector difference u - v (purple)
Plot.arrow([{x1: 0, y1: 0, x2: u1_sub - v1_sub, y2: u2_sub - v2_sub}], {
x1: "x1", y1: "y1", x2: "x2", y2: "y2",
stroke: "purple", strokeWidth: 3, fill: "purple"
}),
// Vector from v to u (alternative representation)
Plot.arrow([{x1: v1_sub, y1: v2_sub, x2: u1_sub, y2: u2_sub}], {
x1: "x1", y1: "y1", x2: "x2", y2: "y2",
stroke: "#ff6600", strokeWidth: 2, fill: "#ff6600",
strokeDasharray: "3,3"
}),
// Labels
Plot.text([
{x: u1_sub/2, y: u2_sub/2 + 0.5, text: "u"},
{x: v1_sub/2, y: v2_sub/2 - 0.5, text: "v"},
{x: -v1_sub/2, y: -v2_sub/2 + 0.5, text: "-v"},
{x: (u1_sub - v1_sub)/2, y: (u2_sub - v2_sub)/2 + 0.8, text: "u-v"}
], {
x: "x", y: "y", text: "text", fontSize: 14, fontWeight: "bold"
})
]
})