Tuesday, February 22, 2022

[How To] Draw Vectors in Python

import numpy as np
import matplotlib.pyplot as plt

x_pos = np.linspace(0,5,10)
y_pos = np.linspace(0,10,10)
x_dir = y_dir = np.zeros((10,10))
plt.quiver(x_pos, y_pos, x_dir, y_dir, scale=1)

x_pos = [2.5,2.5]
y_pos = [5,5]
x_dir = [1.5,1]
y_dir = [1.5,2.5]
plt.quiver(x_pos, y_pos, x_dir, y_dir, scale=10)

x1, y1 = [0,5], [5,5]
x2, y2 = [2.5,2.5], [0,10]
plt.plot(x1, y1, x2, y2)

x_pos = [3.75,3.75]
y_pos = [9.75,9.75]
x_dir = [-1.5,-1]
y_dir = [-1.5,-2.5]
plt.quiver(x_pos, y_pos, x_dir, y_dir, scale=10)

plt.axis('off')

plt.show()

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.