首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >python中的3d曲线箭头

python中的3d曲线箭头
EN

Stack Overflow用户
提问于 2020-08-23 18:52:32
回答 1查看 289关注 0票数 2

请问如何在3d中画一个弯曲的箭头?我的意思是类似于2D中的情况:

代码语言:javascript
复制
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()
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-08-23 19:44:00

您需要扩展FancyArrowPatch。其思想是截取3D坐标参数。其他参数直接传递给FancyArrowPatch美工人员。

代码语言:javascript
复制
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]是终点坐标。

参考资料:

Plotting a 3d cube, a sphere and a vector in Matplotlib

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63546097

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档