栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何在Matplotlib中旋转花式箭头

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何在Matplotlib中旋转花式箭头

由于箭头的头和尾是在不同的坐标系中指定的,因此我似乎唯一的选择是围绕圆心分别旋转坐标。

import numpy as npimport matplotlib.pyplot as pltimport matplotlib.transforms as mtransfig, ax = plt.subplots()#Arrow represent the wind direction#Arrow should rotate as per the specified degree, (0 degree is North)x3=5.0y3=5.0#Draw Circle#CENTER POINTCircle1 = plt.Circle((x3, y3), 0.1, color='blue', fill=True)ax.add_artist(Circle1)#CIRCLECircle2 = plt.Circle((x3, y3), 6, color='blue', fill=False)ax.add_artist(Circle2)def winddirectionarrow(ax, xy, deg):    m1 = np.array( (-1, 1) )    m2 = np.array( (0, 1) )    s1 = np.array( (0.5, 1.8) )    s2 = np.array( (20, 50) )    xy = np.array(xy)    rot = mtrans.Affine2D().rotate_deg(deg)    #Wind Direction Arrow    cncs = "angle3,angleA={},angleB={}".format(deg,deg-90)    kw = dict(xycoords='data',textcoords='offset points',size=20,   arrowprops=dict(arrow, fc="0.6", ec="none",        connectionstyle=cncs))    #LEFT ARROW    ax.annotate('', xy=xy + rot.transform_point(m1*s1),          xytext=rot.transform_point(m1*s2), **kw)    #CENTER ARROW    ax.annotate('', xy=xy + rot.transform_point(m2*s1),          xytext=rot.transform_point(m2*s2), **kw)    #RIGHT ARROW    ax.annotate('', xy=xy + rot.transform_point(s1),          xytext=rot.transform_point(s2), **kw)winddirectionarrow(ax, (x3,y3),  45)winddirectionarrow(ax, (x3,y3), -60)winddirectionarrow(ax, (x3,y3), 170)ax.set_aspect('equal') ax.set_xlim([-2.5,12.5])ax.set_ylim([-3,15])plt.show()



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/648443.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号