Python Forum
Plotting Help - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Plotting Help (/thread-25855.html)



Plotting Help - mogsb19 - Apr-13-2020

Hello, I'm pretty new to python and have been trying to create a graph with 6 different vectors with different colour arrows. I can't seem to get the graph I want though, could someone help see what went wrong in my code? Thanks.


import matplotlib.pyplot as plt
print('Matrix Vector Plots')
A = np.array([[1,1.5],[0,2]])
print('A=')
print(A)
l,v=np.linalg.eig(A)
print('Eigenvalues:')
print(l)
print('Eigenvectors:')
print(v)
eigen1 = ([1,0])
eigen2 = ([0.83205029,0.5547002])
v_1 = ([1,2])
v_2 = ([0,1])
v_3 = ([-1,2])
v_4 = ([-0.5,1])

vectors = [np.array([1,2]), np.array([0,1]), np.array([-1,2]), np.array([-0.5]), np.array([1,0]), np.array([0.83205029,0.5547002])]
colors = ['blue','green','yellow','red','purple','orange']

for i in range(6):
    def plot_vector1(v_1, blue): 
        plt.arrow(1,2, v_1[1], v_1[2], color = blue, head_width=0.2)
    def plot_vector2 (v_2, green): 
        plt.arrow (0,1, v_2[0], v_2[1], color = green, head_width =0.2)
    def plot_vector3 (v_3, yellow): 
        plt.arrow (-1,2, v_3[-1], v_3[2], color = yellow, head_width =0.2)
    def plot_vector4 (v_4, red): 
        plt.arrow (-0.5,1, v_4[-0.5], v_4[1], color = red, head_width =0.2)
    def plot_vector5 (eigen1, purple): 
        plt.arrow (1,0, eigen1[1], eigen1[0], color = purple, head_width =0.2)
    def plot_vector6 (eigen2, orange): 
        plt.arrow (0.83205029,0.5547002, eigen2[0.83205029], eigen2[0.5547002], color = orange, head_width =0.2)

plt.axis('equal')
plt.xlim(-5,5)
plt.ylim(-5,5)

print(plt.plot(vectors))