Reputation: 6369
I am trying to do a quiver plot of three arrows in the x, y and z direction with the arrow colors being green red and blue. For some reason, the lines are the right color but the arrow head is the wrong color and I am not sure how to fix. Here is my code:
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()
Upvotes: 5
Views: 4818
Reputation: 18822
In quiver
, if a list of colors is specified as option colors=..
, color cycle is in effect for all line segments, including all parts of the arrows.
To get 3 arrows of different colors, you can use 3 quiver
statements, each with different color.
Method1
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')
Method2
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_)
Upvotes: 2