gpt4 book ai didi

python - Matplotlib 3D Quiver 图使线条颜色正确,但箭头颜色错误

转载 作者:行者123 更新时间:2023-12-04 03:46:48 26 4
gpt4 key购买 nike

我正在尝试在 x、y 和 z 方向上绘制三个箭头的箭袋图,箭头颜色为绿色、红色和蓝色。出于某种原因,线条颜色正确,但箭头颜色错误,我不知道如何修复。这是我的代码:

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

fig = plt.figure()
ax = fig.gca(projection='3d')
cols = ['r', 'g', 'b']

quivers = ax.quiver([0,0,0],[0,0,0],[0,0,0],[1,0,0],[0,1,0],[0,0,1], colors=cols)

ax.set_xlim3d([-2.0, 2.0])
ax.set_xlabel('X')

ax.set_ylim3d([-2.0, 2.0])
ax.set_ylabel('Y')

ax.set_zlim3d([-2, 2])
ax.set_zlabel('Z')
plt.show()
Quiver plot

最佳答案

quiver , 如果颜色列表被指定为选项 colors=.. ,颜色循环对所有线段有效,包括箭头的所有部分。
要获得 3 个不同颜色的箭头,可以使用 3 quiver声明,每一个都有不同的颜色。
方法一

ax.quiver([0],[0],[0],[1],[0],[0], colors='r')
ax.quiver([0],[0],[0],[0],[1],[0], colors='g')
ax.quiver([0],[0],[0],[0],[0],[1], colors='b')
方法 2
fr = [(0,0,0), (0,0,0), (0,0,0)]
to = [(1,0,0), (0,1,0), (0,0,1)]
cr = ["red", "green", "blue"]
for (from_, to_, colr_) in zip(fr,to,cr):
ax.quiver(*from_, *to_, colors=colr_)

关于python - Matplotlib 3D Quiver 图使线条颜色正确,但箭头颜色错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65039988/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com