Borrar filtros
Borrar filtros

Subplot SCATTERHIST using UIPANEL

6 visualizaciones (últimos 30 días)
Giulia Slaviero
Giulia Slaviero el 25 de En. de 2022
Respondida: Jaswanth el 17 de Oct. de 2023
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!

Respuestas (1)

Jaswanth
Jaswanth el 17 de Oct. de 2023
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.

Categorías

Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by