Not asking anyone to do this for me. But I would like to be able to create something along the lines of this.... Excuse the drawing it isn't the best
Currently my code is looking like this:
import numpy as np
import matplotlib.pyplot as plt
plt.grid()
plt.plot([0, 5 * np.cos(0)], [0, 5 * np.sin(0)])
plt.plot([0, -5 * np.cos(120)], [0, 5 * np.sin(120)])
plt.plot([0, 5 * np.cos(390)], [0, 5 * np.sin(390)])
plt.ylabel('Vectors')
plt.show()
This is the first thing I have tried to plot using a computer. I have a project i'm doing at college and I would rather plot it with a computer than do it by hand as I think it looks neater. Any help or pointers would be greatly appreciated.
Thank you
You can use the plt.arrow(x, y, dx, dy)
-function for this. It will make an arrow from (x, y)
spanning a distance (dx, dy)
in each direction. Below is some example code, and I wrote it very "long", but when you understand how to use it I'm sure you can make it more compact if you like to.
import numpy as np
import matplotlib.pyplot as plt
plt.grid()
x = 0
y = 0
dx = 5 * np.cos(0)
dy = 5 * np.sin(0)
plt.arrow(x, y, dx, dy, head_width=0.1, head_length=0.5, fc='b', ec='b')
x = 0
y = 0
dx = 5 * np.cos(390)
dy = 5 * np.sin(390)
plt.arrow(x, y, dx, dy, head_width=0.1, head_length=0.5, fc='g', ec='g')
x = 0
y = 0
dx = -5 * np.cos(120)
dy = 5 * np.sin(120)
plt.arrow(x, y, dx, dy, head_width=0.1, head_length=0.5, fc='r', ec='r')
plt.ylabel('Vectors')
plt.xlim(-5.5, 5.5)
plt.ylim(-5.5, 5.5)
plt.show()