MATLAB Answers


PNG as figure background

Asked by Andrew McCall on 24 Sep 2017
Latest activity Commented on by Mahmud Khan on 2 Nov 2018
I am trying to generate a figure window with a saved PNG as the background. It will have a fluid simulation on top of it and all I want to do it have this saved PNG be the background. Similar to what set(gca,'Color', k) would do but instead of having the color I want to have it be a figure. Any thoughts?


Sign in to comment.

2 Answers

Answer by Chad Greene
on 24 Sep 2017
Edited by Chad Greene
on 24 Sep 2017

Try this. Start by plotting whatever data you have, then load the png image and plot it with image. Use the limits of the current axes (by xlim and ylim) as the x,y coordinates of the image edges. Some images might be flipped in the vertical direction, so you may have to use -ylim when you call imagesc. The uistack call just sends the image down to the bottom of the stack.
x = 1:500;
y = sind(x);
axis tight;
hold on
I = imread('peppers.png');
h = image(xlim,-ylim,I);