Insert Background Image Behind Subplots

12 次查看(过去 30 天)
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)))

采纳的回答

Geoff Hayes
Geoff Hayes 2020-3-30
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
  1 个评论
Hannah Germaine
Hannah Germaine 2020-4-9
Thank you Geoff, this worked perfectly! I simply modified the axes of the figure to:
hAxes = axes('Parent', hFig, 'units', 'normalized', 'position',[0.1300 0.1100 0.7750 0.8150]);

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Visual Exploration 的更多信息

产品


版本

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by