gpt4 book ai didi

python - 带箭头的 matplotlib 3d 线图无法接受 kwargs

转载 作者:行者123 更新时间:2023-11-30 23:02:43 26 4
gpt4 key购买 nike

为什么会产生错误? ax.quiver 中的 kwarg 枢轴会导致代码失败,但没有 kwarg 也能正常工作。错误消息也不是很有帮助。我正在使用 Python 3.4 和 matplotlib 1.4.3。谢谢。

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')

错误信息

---------------------------------------------------------------------------
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

最佳答案

您需要更新 matplotlib。

来自documentation of version 1.5.0 (第 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

documentation of version 1.4.3 相同(第 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

该功能在 1.4.3 中完全缺失,这也解释了为什么没有信息丰富的错误消息:pivot 关键字被传递给 LineCollection,这可以没有任何意义。

关于python - 带箭头的 matplotlib 3d 线图无法接受 kwargs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34386078/

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