【问题标题】:How to plot vector addition in Matplotlib?如何在 Matplotlib 中绘制向量加法?
【发布时间】:2021-12-30 04:13:09
【问题描述】:

我正在尝试绘制矢量加法,但没有得到预期的结果,我对 3D 绘图完全陌生,我需要认真的帮助 我的情节是这样的:

我想要的是将绿线连接到两个箭头的头部。我的代码如下所示:

import numpy as np
import matplotlib.pyplot as plt

u = np.array([1, 2, 3])   # vector u
v = np.array([5, 6, 2])   # vector v:
  


fig = plt.figure()
ax = plt.axes(projection = "3d")

start = [0,0,0]
ax.quiver(start[0],start[1],start[2],u[0],u[1],u[2],color='red')
ax.quiver(start[0],start[1],start[2],v[0],v[1],v[2])
ax.quiver(v[0],v[1],v[2],u[0],u[1],u[2],color="green")
ax.set_xlim([-1,10])
ax.set_ylim([-10,10])
ax.set_zlim([0,10])



plt.show()

如有错误请见谅,谢谢

【问题讨论】:

    标签: python matplotlib 3d


    【解决方案1】:

    是向量相加,只是向量相加

    sum_vector = u+v
    ax.quiver(start[0], start[1], start[2], sum_vector[0], sum_vector[1], sum_vector[2],  color="green")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-06
      • 2023-03-06
      • 1970-01-01
      • 2016-10-05
      • 2021-02-02
      • 2012-08-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多