Zalgorithm

Matplotlib PyPlot examples (for reference)

Basic matplotlib.pyplot examples.

Plot a point on the Cartesian plane

import matplotlib.pyplot as plt

fig, ax = plt.subplots()

ax.plot(3, 4, "ro", markersize=8)

ax.set_xlim(-5, 5)
ax.set_ylim(-5, 5)

ax.set_xlabel("x")
ax.set_ylabel("y")

ax.set_xticks(range(-5, 6))
ax.set_yticks(range(-5, 6))

ax.grid(True, alpha=0.3)

ax.axhline(y=0, color="k", linewidth=0.5)
ax.axvline(x=0, color="k", linewidth=0.5)

ax.set_aspect("equal")

plt.show()

Plot a vector on the Cartesian plane

Plot a vector on the Cartesian plane and optionally save the plot as an image:


import matplotlib.pyplot as plt

fig, ax = plt.subplots()


ax.quiver(0, 0, 3, 4, angles="xy", scale_units="xy", scale=1, color="b", width=0.006)
ax.annotate("(3,4)", (3, 4))
ax.set_xlim(-5, 5)
ax.set_ylim(-5, 5)

ax.set_xlabel("x")
ax.set_ylabel("y")

ax.set_xticks(range(-5, 6))
ax.set_yticks(range(-5, 6))

ax.grid(True, alpha=0.3)

ax.axhline(y=0, color="k", linewidth=0.5)
ax.axvline(x=0, color="k", linewidth=0.5)

ax.set_aspect("equal")

# plt.savefig("vector_3_4.png")

plt.show()

Plot the same 2D vector from two different origins

import matplotlib.pyplot as plt

fig, ax = plt.subplots()

# same vector drawn from two different origins
# note that `quiver` args are (seem to be) (origin_x, origin_y, vector_[0], vector_[1])
# (I could look that up to confirm)

ax.quiver(0, 0, 3, 4, angles="xy", scale_units="xy", scale=1, color="b", width=0.006)
ax.annotate("(3,4)", (3, 4))

ax.quiver(0, 2, 3, 4, angles="xy", scale_units="xy", scale=1, color="r", width=0.006)
ax.annotate("(3,4)", (3, 6))

ax.set_xlim(-10, 10)
ax.set_ylim(-10, 10)

ax.set_xlabel("x")
ax.set_ylabel("y")

ax.set_xticks(range(-10, 11))
ax.set_yticks(range(-10, 11))

ax.grid(True, alpha=0.3)

ax.axhline(y=0, color="k", linewidth=0.5)
ax.axvline(x=0, color="k", linewidth=0.5)

ax.set_aspect("equal")

# plt.savefig("vector_3_4_two_origins.png")

plt.show()