Home > front end >  pyplot drawing on an angle
pyplot drawing on an angle

Time:11-12

I'm trying to draw a couple of vectors with pyplot.

My approach is to define first the plot size (or axis values), as this will change depending on the job run.

pretty much what i need to do is to draw a straight, upwards-facing vector.

So for the test i am using the same values for x-axis, and two different ones for Y (as that would give me an vertical vector)

problem I face is - whatever i am doing, i can't seem to make the vector straight. It always gets rotated.

Does anyone know what reason there might be for it ?

my current code

import matplotlib.pyplot as plt
import math

start = (162305,299400,162890,299400) #define coordinates for vector

#define plot axis values
top = 163440
bottom = 161910
left = 299595
right = 300510

fig, ax = plt.subplots()

ax.quiver(start[0],start[1],start[2],start[3])

plt.xlim(left,right)
plt.ylim(bottom,top)
plt.autoscale()
plt.show()

and the resulting plot enter image description here

CodePudding user response:

Hope this would help!

import matplotlib.pyplot as plt
import math

start = (162305,299400,162890,299400) #define coordinates for vector

#define plot axis values
top = 163440
bottom = 161910
left = 299595
right = 300510

fig, ax = plt.subplots()

ax.quiver(start[0],start[1],1,0)
#ax.quiver(x_pos, y_pos, x_dir, y_dir, color)
#give the x_pos, y_pos value
#x_dir=1, y_dir=1, meaning 45 degree angle
#x_dir=1, y_dir=0, meaning 0 degree angle
#x_dir=0, y_dir=1, meaning 90 degree angle
# you put x_dir=start[2] and y_dir=start[3], making an arbitary angle of atan 
#(y_dir/x_dir) which makes the angled arrow

plt.xlim(left,right)
plt.ylim(bottom,top)
plt.autoscale()
plt.show()
  • Related