我正在嘗試用 pyplot 繪制幾個向量。
我的方法是首先定義繪圖大小(或軸值),因為這將根據作業運行而改變。
我幾乎需要做的是畫一個筆直的、朝上的矢量。
因此,對于測驗,我對 x 軸使用相同的值,對 Y 使用兩個不同的值(因為這會給我一個垂直向量)
我面臨的問題是 - 無論我在做什么,我似乎都無法使向量變直。它總是被旋轉。
有誰知道這可能是什么原因?
我當前的代碼
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()
以及由此產生的情節
uj5u.com熱心網友回復:
希望這會有所幫助!
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()
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/532764.html
