How to insert a colorcloud into a subplot

1 view (last 30 days)
Hi there,
I was wondering how can I add a colorcloud graph into a subplot. I see that kind of graph in the Image Processing Toolbox / Color Thresholder app.
Here is the code that I use to insert different Images and graph into a figure:
Titles are not in the right position. Also the third plot overlape the 5th and sometimes make the 3rd in half size.
I appreciate your help.
RGB = imread('peppers.png');
grayImage = rgb2gray(RGB);
subplot(3, 3, 1);
imshow(RGB);
% Maximize the figure window.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
% Force it to display RIGHT NOW
drawnow;
caption = sprintf('Title 1');
title(caption, 'FontSize', 10);
axis image;
subplot(3, 3, 2);
imshow(grayImage);
drawnow;
caption = sprintf('Title 2');
title(caption, 'FontSize', 10);
axis image;
%hpanel = subplot(3, 3, 3);
hpanel = uipanel('Parent',gcf,'Position', [0.6, 0.6, 0.4, 0.4],'Tag','ui');
colorcloud(RGB,'rgb','Parent',hpanel);
drawnow;
title('Title 3', 'FontSize', 10);
subplot(3, 3, 4);
imshow(grayImage)
title('Title 4', 'FontSize', 10);
[pixelCount, grayLevels] = imhist(grayImage);
subplot(3, 3, 5);
bar(pixelCount);
title('Title 5', 'FontSize', 10);
xlim([0 grayLevels(end)]); % Scale x axis manually.
grid on;

Accepted Answer

Cris LaPierre
Cris LaPierre on 9 Mar 2019
Edited: Cris LaPierre on 9 Mar 2019
I'd probably set up all the plots, then add the uipanel last.
figure;
% Maximize the figure window.
set(gcf,'Visible','on','units','normalized','outerposition',[0 0 1 1])
RGB = imread('peppers.png');
grayImage = rgb2gray(RGB);
subplot(3, 3, 1);
imshow(RGB);
title('Title 1', 'FontSize', 10);
axis image;
subplot(3, 3, 2);
imshow(grayImage);
title('Title 2', 'FontSize', 10);
axis image;
subplot(3, 3, 3)
title('Title 3', 'FontSize', 10);
axis off
subplot(3, 3, 4);
imshow(grayImage)
title('Title 4', 'FontSize', 10);
[pixelCount, grayLevels] = imhist(grayImage);
subplot(3, 3, 5);
bar(pixelCount);
title('Title 5', 'FontSize', 10);
xlim([0 grayLevels(end)]); % Scale x axis manually.
grid on;
% Add uipanel last
hpanel = uipanel('Parent',gcf,'Position', [0.67, 0.7, 0.25, 0.2]);
colorcloud(RGB,'rgb','OrientationAxesColor','none','Parent',hpanel);
  3 Comments
Cris LaPierre
Cris LaPierre on 9 Mar 2019
Edited: Cris LaPierre on 9 Mar 2019
Sure. Specify the parent when creating suplot 4 to bring the focus back to the figure window instead of the UIpanel.
f = figure;
% Maximize the figure window.
set(gcf,'Visible','on','units','normalized','outerposition',[0 0 1 1])
RGB = imread('peppers.png');
grayImage = rgb2gray(RGB);
subplot(3, 3, 1);
imshow(RGB);
title('Title 1', 'FontSize', 10);
axis image;
subplot(3, 3, 2);
imshow(grayImage);
title('Title 2', 'FontSize', 10);
axis image;
ax=subplot(3, 3, 3)
title('Title 3', 'FontSize', 10);
axis off
% Add uipanel last
hpanel = uipanel('Parent',f,'Position', [0.67, 0.7, 0.25, 0.2]);
colorcloud(RGB,'rgb','OrientationAxesColor','none','Parent',hpanel);
subplot(3, 3, 4,'Parent',f);
imshow(grayImage)
title('Title 4', 'FontSize', 10);
[pixelCount, grayLevels] = imhist(grayImage);
subplot(3, 3, 5);
bar(pixelCount);
title('Title 5', 'FontSize', 10);
xlim([0 grayLevels(end)]); % Scale x axis manually.
grid on;
This allows you to create them sequentially.
emami.m
emami.m on 9 Mar 2019
I appreciate your reply, that is exactly what I was looking for.

Sign in to comment.

More Answers (0)

Categories

Find more on Graphics Performance in Help Center and File Exchange

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!