Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matplotlib: How to make scatter plot of arbitrary pyplot figures

This is a question linked to this well received one. In that question I see an answers on how to plot images (or different images) at different coordinates like a scatter plot.

Using TextArea I can put little strings instead of images at different coordinates.

How about if I want to put a mini version of a plot/image generated by matplotlib itself? Suppose I want instead of using an image.jpg I want to use the result of plt.stem(arr) as the image in the scatter plots.

How can I do this? How about a miniature version of the output of plt.plot(x, y)?

I tried modifying the function given in the linked question to be like:

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

But that gives an error: AttributeError: 'StemContainer' object has no attribute 'is_transform_set'

EDIT: From the linked question:

"…. 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."

this would be a desirable feature in an accepted answer because on zooming in one would like to see the relative positions of the scatter points. If the scatter plotted image did not maintain a fixed size (relative to the screen as opposed to current axis limits), then zooming in would be of little help.

like image 701
ITA Avatar asked May 26 '19 00:05

ITA


People also ask

What is CMAP in scatter plot?

cmap: A map of colors to use in the plot.


1 Answers

You could try something like: https://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.inset_axes.html

like image 74
Jody Klymak Avatar answered Oct 22 '22 07:10

Jody Klymak