Subplot SCATTERHIST using UIPANEL

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