필터 지우기
필터 지우기

Subplot SCATTERHIST using UIPANEL

조회 수: 6 (최근 30일)
Giulia Slaviero
Giulia Slaviero 2022년 1월 25일
답변: Jaswanth 2023년 10월 17일
Hi everyone,
I'm trying to subplot multiple scatterhist plots in one figure. I've found in older threads that it is possible to do it using uipanel, as in the following example:
load fisheriris.mat;
x = meas(:,1);
y = meas(:,2);
%
% create two separate figures with the two scatterplots in
h1 = figure
scatterhist(x,y,'Group',species)
h2 = figure
scatterhist(x,y,'Group',species)
%
% create third figure split into two uipanels
p = figure
u1 = uipanel(p,'position',[0,0,0.5,1]);
u2 = uipanel(p,'position',[0.5,0,0.5,1]);
%
% get all children from each figure and move to the uipanels
set(get(h1,'Children'),'parent',u1);
set(get(h2,'Children'),'parent',u2);
Unfortunately there are two problems.
1- It is not possible to plot a scatterhist figure with legend (using Matlab 2017a)
Error using matlab.graphics.illustration.Legend/setParentImpl
A legend and its associated axes must have the same parent.
2- It seems like this sintax does not work for Matlab 2020 and after:
Error using matlab.graphics.Graphics/set
Parent must be a Figure
Any idea how to fix this prolems? Thanks!

답변 (1개)

Jaswanth
Jaswanth 2023년 10월 17일
Hi Giulia Slaviero,
I understand that you want to subplot multiple “scatterhist” plots on the same figure. In this case, to do so, after assigning the “uipanel” positions on the created figure, you can directly assign the parent container of the “scatterhist” in the function itself.
For your better understanding on the same, I am attaching a sample code below:
load fisheriris.mat;
x = meas(:, 1);
y = meas(:, 2);
% Create the first figure and uipanels
p = figure;
u1 = uipanel(p, 'position', [0, 0, 0.5, 1]);
u2 = uipanel(p, 'position', [0.5, 0, 0.5, 1]);
% Create the scatter plots with histograms on the side
h1 = scatterhist(x, y, 'Group', species, 'parent', u1);
h2 = scatterhist(x, y, 'Group', species, 'parent', u2);
The above code has been recreated in MATLAB version R2023a and R2020a and is providing the output as expected.
I hope this helps!
Regards,
Jaswanth.

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by