matplotlib 趋势图 折线图 插入图片

参考链接:https://blog.csdn.net/weixin_41846769/article/details/113028800

from matplotlib.offsetbox import OffsetImage,  AnnotationBbox

arr_img = plt.imread('data/ima.png')

ax = plt.plot([1,100], [100, 1])
imagebox = OffsetImage(arr_img, zoom=0.1)
# imagebox.image.axes = ax
# 使用AnnotationBbox添加到画布
ab = AnnotationBbox(imagebox, [0, 0],
                   xybox=(100, 100),
                   pad=0)
ax[0].axes.add_artist(ab)

在这里插入图片描述

其中不一定要加
imagebox.image.axes = ax