我想繪制三個向量b、d和d-b。當然,這意味著 的尾巴d-b碰到 的頭b。我正在使用
import numpy as np
import matplotlib.pyplot as plt
b = np.array([4, 1])
d = np.array([-3, 3])
m = d-b
o = np.array([
[0, 0, b[0]],
[0, 0, b[1]]
])
v = np.array([
[b[0], b[1]],
[d[0], d[1]],
[m[0], m[1]]
])
fig, ax = plt.subplots()
ax.quiver(*o, v[:, 0], v[:, 1])
plt.show()
uj5u.com熱心網友回復:
根據
uj5u.com熱心網友回復:
像這樣存盤向量的坐標更方便:
S = np.stack([*o, v[:, 0], v[:, 1]])
>>> S
array([[ 0, 0, 4],
[ 0, 0, 1],
[ 4, -3, -7],
[ 1, 3, 2]])
現在您可以通過這種方式訪問??起點和方向的坐標:
>>> S[:2], S[2:]
(array([[0, 0, 4],
[0, 0, 1]]),
array([[ 4, -3, -7],
[ 1, 3, 2]]))
以及終點坐標:
>>> S[:2] S[2:]
array([[ 4, -3, -3],
[ 1, 3, 3]])
所以你可以得到一個平面上的所有點:
>>> pts = np.hstack([S[:2], S[:2] S[2:]])
array([[ 0, 0, 4, 4, -3, -3],
[ 0, 0, 1, 1, 3, 3]])
對于后面的部分,請查看jylls并使用的答案:
plt.quiver(*S, angles='xy', scale_units='xy', scale=1)
最后,當你有一個很好的情節時,你可能會對如何為你的情節指定邊界感興趣。你可以這樣做:
x_min, y_min = np.min(pts, axis=1)
x_max, y_max = np.max(pts, axis=1)
plt.xlim([x_min, x_max])
plt.ylim([y_min, y_max])
plt.show()

轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/412351.html
標籤:
下一篇:用偶數和奇數格式化Numpy陣列
