简体   繁体   English

在python中使用箭袋绘制3d矢量

[英]using quiver in python to plot a 3d vector

Super simple question, I know, but it's my first day using python and have to learn to use it quickly. 我知道这是一个非常简单的问题,但这是我使用python的第一天,必须学习快速使用它。 I'd like to use quiver(it has to be quiver) to draw 3D vector. 我想使用颤抖(必须颤抖)来绘制3D矢量。 to make it simple, if I want to draw the vector (1,1,1) and see it like in the following picture(in the right directions of course), how can I do it? 简单起见,如果我想绘制矢量(1,1,1)并在下图中(当然,朝正确的方向)看到它,该怎么办? this is what I've been trying to do: 这就是我一直在尝试做的事情:

import matplotlib.pyplot as plt
plt.quiver(0, 0, 0, 1, 1, 1, scale=1, color='g')

在此处输入图片说明

plt.quiver only works for 1D and 2D arrays. plt.quiver仅适用于一维和二维阵列。 You should use mplot3d to show your figure in 3 dimensions: 您应该使用mplot3d以3维显示图形:

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.set_xlim3d(0, 0.8)
ax.set_ylim3d(0, 0.8)
ax.set_zlim3d(0, 0.8)
ax.quiver(0, 0, 0, 1, 1, 1, length = 0.5, normalize = True)
plt.show()

I recommend you read the documentation on pyplot.quiver and axes3d.quiver . 我建议您阅读pyplot.quiveraxes3d.quiver上的文档。

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

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