nagordon
nagordon

Reputation: 1367

matplotlib 3d line plot with arrow fails to accept kwargs

Why does this produce an error? The kwarg pivot in ax.quiver causes the code to fail, but it works without the kwarg. The error message is not very helpful either. I am using Python 3.4 and matplotlib 1.4.3. Thanks.

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()

ax = plt.axes(projection='3d')

x=[0,0,4,4]
y=[0,5,5,5]
z=[0,0,0,-2]

ax.plot(x, y, z, '-b', linewidth=5)
ax.view_init(30, 30)

ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')

X=[0]
Y=[5]
Z=[0]
U=[-60]
V=[40]
W=[20]

ax.quiver3D(X, Y, Z, U, V, W, pivot='tail')

Error Message

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-37-f68d70030cee> in <module>()
     25 #ax.quiver3D(X, Y, Z, U, V, W)
     26 
---> 27 ax.quiver3D(X, Y, Z, U, V, W, pivot='tail')

C:\Users\neal\Anaconda3\lib\site-packages\mpl_toolkits\mplot3d\axes3d.py in quiver(self, *args, **kwargs)
   2615             lines.append(line)
   2616 
-> 2617         linec = art3d.Line3DCollection(lines, *args[argi:], **kwargs)
   2618         self.add_collection(linec)
   2619 

C:\Users\neal\Anaconda3\lib\site-packages\mpl_toolkits\mplot3d\art3d.py in __init__(self, segments, *args, **kwargs)
    169         Keyword arguments are passed onto :func:`~matplotlib.collections.LineCollection`.
    170         '''
--> 171         LineCollection.__init__(self, segments, *args, **kwargs)
    172 
    173     def set_sort_zpos(self,val):

C:\Users\neal\Anaconda3\lib\site-packages\matplotlib\collections.py in __init__(self, segments, linewidths, colors, antialiaseds, linestyles, offsets, transOffset, norm, cmap, pickradius, zorder, **kwargs)
   1081             pickradius=pickradius,
   1082             zorder=zorder,
-> 1083             **kwargs)
   1084 
   1085         self.set_segments(segments)

C:\Users\neal\Anaconda3\lib\site-packages\matplotlib\collections.py in __init__(self, edgecolors, facecolors, linewidths, linestyles, antialiaseds, offsets, transOffset, norm, cmap, pickradius, hatch, urls, offset_position, zorder, **kwargs)
    133 
    134         self._path_effects = None
--> 135         self.update(kwargs)
    136         self._paths = None
    137 

C:\Users\neal\Anaconda3\lib\site-packages\matplotlib\artist.py in update(self, props)
    755             func = getattr(self, 'set_' + k, None)
    756             if func is None or not six.callable(func):
--> 757                 raise AttributeError('Unknown property %s' % k)
    758             func(v)
    759             changed = True

AttributeError: Unknown property pivot

Upvotes: 1

Views: 1710

Answers (1)

You need to update matplotlib.

From the documentation of version 1.5.0 (page 641):

quiver3D(*args, **kwargs)

Plot a 3D field of arrows.

...

Keyword arguments:

length: [1.0 | float] The length of each quiver, default to 1.0, the unit is the same with the axes

arrow_length_ratio: [0.3 | float] The ratio of the arrow head with respect to the quiver, default to 0.3

pivot: [ ‘tail’ | ‘middle’ | ‘tip’ ] The part of the arrow that is at the grid point; the arrow rotates about this point, hence the name pivot.

Any additional keyword arguments are delegated to LineCollection

The same in the documentation of version 1.4.3 (page 567):

quiver3D(*args, **kwargs)

Plot a 3D field of arrows.

...

Keyword arguments:

length: [1.0 | float] The length of each quiver, default to 1.0, the unit is the same with the axes

arrow_length_ratio: [0.3 | float] The ratio of the arrow head with respect to the quiver, default to 0.3

Any additional keyword arguments are delegated to LineCollection

The feature is simply missing from 1.4.3, which also explains why there isn't an informative error message: the pivot keyword is passed to LineCollection, which can't make any sense of it.

Upvotes: 3

Related Questions