Description
I wanted to visualize better the generated 3D quiver plot by specifiing a custom color for each arrow as follows:
vector3d(x, y, z) -> rgb(x/x_max, y/y_max, z/z_max) where all values are absolute values
After browsing the doc, I came across the colors
argument which is passed to LineCollection
.
After some trial and error, I finally figured out the logic of how the plot is actually drawn:
loop though the vectors to be drawn:
if the norm of the vector is not 0 then:
draw 1 line to represent the main part of the arrow ("-" part of "->")
loop again though the vectors to be drawn:
if the norm of the vector is not 0 then:
draw 2 lines to represent the head part of the arrow (">" part of "->")
For those who may be interested, for my case I have used the following functions as a work around to transform the list of rgb colors for each arrow to the corresponding list which correctly colored the 3D quiver plot:
def repeatForEach(elements, times):
return [element for element in elements for _ in xrange(times)]
def renderColorsForQuiver3d(colors):
# filter out 0-length vector corresponding to rgb=(0,0,0) that won't be drawn
colors = filter(lambda x: x!=(0.,0.,0.), colors)
# set up rgb color for each lines of arrows
return colors + repeatForEach(colors, 2)
My question is: shouldn't it be more user-friendly to just specify a color for each arrow regardless of its length(a.k.a. whether it will actually be drawn)? I suppose the similar problem also exists for customizing other properties like line width.
Matplotlib version
tested with matplotlib 2.0.0, python 2.7 on windows 7 x64 and ubuntu 16.04 x64