Matplotlib图例的箭头

Matplotlib图例的箭头,第1张

Matplotlib图例箭头

您可以添加任意艺人传说命令,如解释在这里

import matplotlib.pyplot as pltf = plt.figure()arrow = plt.arrow(0, 0, 0.5, 0.6, 'dummy',label='My label')plt.legend([arrow,], ['My label',])

箭头美术师不允许使用标记参数,因此您需要做一些额外的手动修改,以替换图例中的标记。

编辑

要获得自定义标记,您需要定义自己的标记

handler_map
。下面的代码是在启发的例子在这里:

from matplotlib.legend_handler import HandlerPatchimport matplotlib.patches as mpatchesdef make_legend_arrow(legend, orig_handle,xdescent, ydescent,width, height, fontsize):    p = mpatches.FancyArrow(0, 0.5*height, width, 0, length_includes_head=True, head_width=0.75*height )    return pf = plt.figure(figsize=(10,6))arrow = plt.arrow(0,0, 0.5, 0.6, 'dummy', label='My label', )plt.legend([arrow], ['My label'], handler_map={mpatches.FancyArrow : HandlerPatch(patch_func=make_legend_arrow),         })


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5664631.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存