Last active
April 23, 2021 17:51
-
-
Save davidrajm/3085724424e8741a3a852090065d14bc to your computer and use it in GitHub Desktop.
This helper script will give a function to plot the given vectors. One can input the 2-tuple vectors in an array and get the plot of them.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def plot_vectors(vectors, title=None): | |
import numpy as np | |
from matplotlib import pyplot as plt | |
# Initiate the plot | |
fig, ax = plt.subplots(figsize = (5,5)) | |
# Draw each vector as quiver plot | |
for x_cor, y_cor in vectors: | |
ax.quiver(0,0,x_cor,y_cor, | |
scale=1,angles='xy', | |
scale_units='xy',color='steelblue') | |
# Calculate the limit | |
limit = np.max(np.abs(vectors))*1.25 | |
ax.set_xlim([-limit, limit]) | |
ax.set_ylim([-limit, limit]) | |
ax.set_aspect('equal') | |
# Make the grid visible | |
ax.grid(True, linewidth = 0.5, alpha= 0.85) | |
# show x-y axis in the center, and hide the frames | |
ax.spines['left'].set_position('center') | |
ax.spines['bottom'].set_position('center') | |
ax.spines['right'].set_color('none') | |
ax.spines['top'].set_color('none') | |
if title != None: | |
plt.title(title) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment