python箭头符号怎么打_python – 箭头的Matplotlib图例

您可以向legend命令添加任意艺术家,如

here所述

import matplotlib.pyplot as plt

f = plt.figure()

arrow = plt.arrow(0, 0, 0.5, 0.6, 'dummy',label='My label')

plt.legend([arrow,], ['My label',])

箭头艺术家不允许使用标记参数,因此您需要进行一些额外的手动修补以替换图例中的标记.

编辑

要获取自定义标记,您需要定义自己的handler_map.以下代码的灵感来自示例here:

from matplotlib.legend_handler import HandlerPatch

import matplotlib.patches as mpatches

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

f = 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),

})

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值