Matplotlib:如何制作任意pyplot图形的散点图

ITA*_*ITA 7 python matplotlib

这是一个与这个广受欢迎的问题有关的问题。在该问题中,我看到了有关如何在散点图等不同坐标上绘制图像(或不同图像)的答案。

使用TextArea我可以将小字符串而不是图像放在不同的坐标处。

如果我想放置由matplotlib本身生成的绘图/图像的迷你版,该怎么办?假设我要使用散点图中的图像作为image.jpg结果,而不是使用I。plt.stem(arr)

我怎样才能做到这一点?微型版本的输出plt.plot(x, y)怎么样?

我试图将链接问题中给出的功能修改为:

def stem_scatter(x, y, arr, ax=None):

    from matplotlib.offsetbox import AnnotationBbox, DrawingArea

    if ax is None:
        ax = plt.gca()
    im = DrawingArea(0.1, 0.1)
    im.add_artist(plt.stem(arr))
    x, y = np.atleast_1d(x, y)
    artists = []
    for x0, y0 in zip(x, y):
        ab = AnnotationBbox(im, (x0, y0), xycoords='data', frameon=False)
        artists.append(ax.add_artist(ab))
    ax.update_datalim(np.column_stack([x, y]))
    ax.autoscale()
    return artists
Run Code Online (Sandbox Code Playgroud)

但这给出了一个错误: AttributeError: 'StemContainer' object has no attribute 'is_transform_set'

编辑:从链接的问题:

"…. but the second has a large advantage. The annotation box approach will allow the image to stay at a constant size as you zoom in."
Run Code Online (Sandbox Code Playgroud)

这将是可接受答案中的一项理想功能,因为在放大时希望看到分散点的相对位置。如果散点图图像没有保持固定大小(相对于屏幕,而不是当前轴限制),则放大将无济于事。