在Matplotlib中绘制图外箭头

21 投票
2 回答
12976 浏览
提问于 2025-04-18 07:53

我有一个这样的网格图,想在上面画一个箭头(在图中用蓝色标出,使用了MS Paint)。请问我该如何通过matplotlib来实现这个呢?我不知道有什么命令可以做到这一点。

在这里输入图片描述

2 个回答

16

在使用 ax.arrow 时,把 clip_on 设置为 False

25
import matplotlib.pyplot as plt

fg = plt.figure(1);
fg.clf();
ax = fg.add_subplot(1,1,1)
ax.annotate('', xy=(0, -0.1), xycoords='axes fraction', xytext=(1, -0.1), 
            arrowprops=dict(arrowstyle="<->", color='b'))
ax.grid(True)
fg.canvas.draw()

给出的结果是 在这里输入图片描述

撰写回答