Clear Filters
Clear Filters

How to transfer a figure with all of its components to a subplot

4 views (last 30 days)
Hello there, community.
I have a graphic that I create on a regular basis for various purposes and data analysis.
Issue-1
I'd like to display Pixel Information for each subplot, but it appears that I'm only getting the last subplot to do so, rather than each subplot displaying Pixel Information.
Issue-2 (suggestion)
At the same time, I disagree with having an additional main figure fig1 in my instance and instead only getting the subplots with Pixel Information.
Could you please give your ideas on how to do it?
Here is the test code which is not working as per the expectation
fig1 = figure;
ax = axes('parent',fig1);
imgdiff = rand(90,120);
h=imshow(imgdiff,[]);
xlabel(ax,'x');
ylabel(ax,'y');
title(ax,'source');
fig2 = figure;
%subplot-1
ax1 = subplot(2,2,1,'parent',fig2);
h1 = imagesc(imgdiff);
title('imgdiff'); axis on;
hText = impixelinfoval(fig2,h1);set(hText,"FontWeight","bold");set(hText,"FontSize",10);
%subplot-2
ax2 = subplot(2,2,2,'parent',fig2);
h2 = imagesc(medfilt2(imgdiff));
title('medfilt2'); axis on;
hText = impixelinfoval(fig2,h2);
set(hText,"FontWeight","bold");set(hText,"FontSize",10);
%subplot-3
ax3 = subplot(2,2,3,'parent',fig2);
h3 = imagesc(wiener2(imgdiff));
title('wiener2'); axis on;
hText = impixelinfoval(fig2,h3);
set(hText,"FontWeight","bold");set(hText,"FontSize",10);
%subplot-4
ax4 = subplot(2,2,4,'parent',fig2);
h4 = imagesc(entropyfilt(imgdiff));
title('entropyfilt'); axis on;
hText = impixelinfoval(fig2,h4);set(hText,"FontWeight","bold");set(hText,"FontSize",10);
axcp = copyobj(ax, fig2);
set(axcp,'Position',get(ax1,'position'));
delete(ax1);% not sure to do or not ??
%delete(ax2);
%delete(ax3);
%delete(ax4);

Accepted Answer

Varun
Varun on 15 May 2023
Edited: Varun on 15 May 2023
I understand you are facing issues with the impixelinfoval function when calling it for each subplot. I ran the attached code on my end and these pointers helped me fix the issue:
  1. I observed that the problem with impixelinfoval persists only if the first image is plotted in ax1. This is because the code eventually deletes the “ax1” object while plotting the second figure. As you mentioned, you do not want the main figure but only the subplots, you could simply omit plotting the first image. It solves the issue with the rest of the subplots.
  2. Instead of adding the impixelinfoval function individually for each subplot, you can call it for the whole figure at the same time. This is done by passing an array of image objects to the function as demonstrated in the following code snippet:
imgdiff = rand(90,120);
fig1 = figure;
%subplot-1
ax2 = subplot(3,1,1);
h2 = imagesc(medfilt2(imgdiff));
title("medfilt2");
axis on;
%subplot-2
ax3 = subplot(3,1,2);
h3 = imagesc(wiener2(imgdiff));
title("wiener2");
axis on;
%subplot-3
ax4 = subplot(3,1,3);
h4 = imagesc(entropyfilt(imgdiff));
title("entropyfilt");
axis on;
h = impixelinfoval(fig1,[h2,h3,h4]);
set(h,"FontWeight","bold");
set(h,"FontSize",10);

More Answers (0)

Categories

Find more on Visual Exploration in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!