7

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.

7
  • A bit hacky, but you can use plt.savefig to save a picture, then use the method in the linked question Commented May 31, 2019 at 8:57
  • @BlackBear Indeed that (or a variation of that using PIL to avoid saving to disk) is what I am currently doing … but if you have a scatter plot with a couple of hundred points it doesn't seem like the best way. Commented May 31, 2019 at 9:01
  • You already got an answer by one of the matplotlib developpers. What is the bounty for? Did you try using an inset axes? Commented Jun 1, 2019 at 1:24
  • @ImportanceOfBeingErnest I am not sure it is really an answer, rather more of a suggestion in a possible direction … which may or may not work. And ... no I didn't try, mostly because the link in the answer features a prominent warning that the feature is experimental and the API may change. Commented Jun 1, 2019 at 7:19
  • Also 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.". I am not completely sure, but my experiments suggested this is not true for a naive inset_axes approach. Commented Jun 1, 2019 at 7:36

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.