请问如何在3d中画一个弯曲的箭头?我的意思是类似于2D中的情况:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as patches
fig, ax = plt.subplots()
plt.rcParams["figure.figsize"] = [10, 3]
plt.xlim(-50,150)
plt.ylim(-60,165)
style="Simple,tail_width=0.5,head_width=4,head_length=8"
kw = dict(arrowstyle=style)
a3 = patches.FancyArrowPatch((0, 0), (99, 100),connectionstyle="arc3,rad=-0.3", **kw)
for a in [a3]:
plt.gca().add_patch(a)
plt.show()发布于 2020-08-23 19:44:00
您需要扩展FancyArrowPatch。其思想是截取3D坐标参数。其他参数直接传递给FancyArrowPatch美工人员。
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import FancyArrowPatch
fig = plt.figure()
ax1 = fig.add_subplot(121)
ax1.set_xlim(-50,150)
ax1.set_ylim(-60,165)
style="Simple,tail_width=0.5,head_width=4,head_length=8"
kw = dict(arrowstyle=style)
a1 = FancyArrowPatch((0, 0), (99, 100),connectionstyle="arc3,rad=-0.3", **kw)
ax1.add_patch(a1)
from mpl_toolkits.mplot3d import proj3d
class Arrow3D(FancyArrowPatch):
def __init__(self, xs, ys, zs, *args, **kwargs):
FancyArrowPatch.__init__(self, (0, 0), (0, 0), *args, **kwargs)
self._verts3d = xs, ys, zs
def draw(self, renderer):
xs3d, ys3d, zs3d = self._verts3d
xs, ys, zs = proj3d.proj_transform(xs3d, ys3d, zs3d, renderer.M)
self.set_positions((xs[0], ys[0]), (xs[1], ys[1]))
FancyArrowPatch.draw(self, renderer)
ax2 = fig.add_subplot(122, projection="3d")
a2 = Arrow3D([0, 1], [0, 1], [0, 1], mutation_scale=20,
lw=1, arrowstyle="-|>", color="k", connectionstyle="arc3,rad=-0.3")
ax2.add_artist(a2)
plt.show()xs[0], ys[0], zs[0]是起点坐标,xs[1], ys[1], zs[1]是终点坐标。

参考资料:
https://stackoverflow.com/questions/63546097
复制相似问题