简体   繁体   English

如何在3D中绘制2个向量

[英]How to Plot 2 Vectors in 3D

import numpy as np
import matplotlib
matplotlib.rcParams['backend'] = "Qt4Agg"
import matplotlib.pyplot as plt
import seaborn as sns 
from mpl_toolkits.mplot3d import Axes3D


fig = plt.figure()
ax = fig.gca(projection='3d')

%matplotlib inline
p=np.array([1,-3,5])
q=np.array([3,2,6])
ax.quiver(p,q)
ax.legend()

plt.show()

I'm trying to plot the 2 vectors p and q in 3D. 我正在尝试绘制3D中的两个向量p和q。 I keep getting this error message 我不断收到此错误消息

ValueError: need at least one array to concatenate ValueError:至少需要一个数组来串联

Not sure what I need to do to get this plot to show. 不知道该怎么做才能显示该图。

quiver is for plotting a vector field (for example, the velocity field). quiver用于绘制矢量场(例如速度场)。

You can use plot to plot line between 0 and q (or p) 您可以使用plot在0和q(或p)之间绘制线

ax.plot(*np.vstack([[0,0,0],p]).T)
ax.plot(*np.vstack([[0,0,0],q]).T)

You can use quiver to add arrows at the end of the lines. 您可以使用颤音在行尾添加箭头。

ax.quiver(*q,*q)
ax.quiver(*p,*p)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM