Insert Background Image Behind Subplots
14 views (last 30 days)
Show older comments
Hannah Germaine
on 30 Mar 2020
Commented: Hannah Germaine
on 9 Apr 2020
I'm looking for a way to plot an image behind a grid of subplots in MATLAB. I attempted to do so by plotting an image, and then plotting subplots but removing their backgrounds and axes. I have attached what the background image looks like and what the subplots in front look like.
Here is the stripped down code I used to attempt this setup. It results in only the subplot image file.
box = 20;
i = 10;
x_range = pw_responses(i).x_range; %x range for which to plot background image
y_range = pw_responses(i).y_range; %y range for which to plot background image
im = pref_mat(y_range,x_range); %this plotted image is in the background_im.png file
figure(i)
imagesc(im)
colormap(hsv)
set(gca,'XTick',[], 'YTick', [])
hold on
for j = 1:441 %the following subplots are in the subplots.png file
y_vals = surr_cell_resp(j,:); %response curve
subplot(box+1,box+1,j);
plot(x_vals,y_vals,'k')
set(gca,'visible','off')
set(gca,'XTick',[], 'YTick', [])
end
sgtitle(strcat('PW # = ',string(i)))
0 Comments
Accepted Answer
Geoff Hayes
on 30 Mar 2020
Hannah - How do I add a background image to my GUI or figure window? provides a good answer on how to add a background image to your figure. In your case, I suspect that you could do something like
box = 20;
i = 10;
x_range = pw_responses(i).x_range; %x range for which to plot background image
y_range = pw_responses(i).y_range; %y range for which to plot background image
im = pref_mat(y_range,x_range); %this plotted image is in the background_im.png file
hFig = figure(i);
hAxes = axes('Parent', hFig, 'units', 'normalized', 'position',[0 0 1 1]);
imagesc(im);
colormap(hsv);
set(hAxes, 'HandleVisibility', 'off', 'Visible','off');
for j = 1:441 %the following subplots are in the subplots.png file
y_vals = surr_cell_resp(j,:); %response curve
hSubPlot = subplot(box+1,box+1,j);
plot(x_vals,y_vals,'k')
set(hSubPlot, 'HandleVisibility', 'off', 'Visible','off', 'Color', 'none');
end
More Answers (0)
See Also
Categories
Find more on Visual Exploration 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!