add image to legend label
11 views (last 30 days)
Show older comments
Question is simple. Given a chart with two or more lines, as in:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1384469/image.png)
How to add an image to the legend, instead of a label?
plot(rand(2))
legend('image1','image2')
The above creates the legend with the text labels image1 and image2. Instead of writing something, I want to identify each curve with a different figure. Is it possible?
0 Comments
Answers (2)
Matt J
on 16 May 2023
Edited: Matt J
on 16 May 2023
The easiest way I can think of is to make several subplot axes, including one containing the line plot
subplot(1,2,1); plot(1:5);
ax=subplot(1,2,2);
Then you can manually drag and resize the empty axes and place them overtop the axes with the line plot. Then you can use the axes handles to fill the mini-axes with some image, e.g.,
imagesc(ax,imread('cameraman.tif')); axis(ax,'off')
0 Comments
See Also
Categories
Find more on Legend in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!