How to add histogram to series of scattered plot on the same plot?

1 visualizzazione (ultimi 30 giorni)
Ole il 12 Lug 2020
Commentato: Ole il 13 Lug 2020
I would like to add hitogram for each scatter plot.
The code below plots in different color each slice of 3 dim scatter matrix.
I would like to replace 'scatter' with 'scatterhist' but the code does not work anymore.
n = [1:1:10]; % X
m = [1:1:3]; % Y
z1 = rand(1,20);
z2 = rand(1,20);
zr1 = reshape(z1,1,1,[]); % Z
zr2 = reshape(z2,1,1,[]); % Z
F1 = meshgrid(n,m).*zr1; %XYZ
F2 = meshgrid(n,m).*zr2; %XYZ
C = jet(length(n))
for en = 1:length(n)
for pll = 1:length(m)
scatter(reshape(F1(pll,en,:),1,[]),reshape(F2(pll,en,:),1,[]),[],C(en,:)); % ? scatterhist
hold on
end
end
hold off
0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

Risposta accettata

Tommy il 13 Lug 2020
scatterhist() uses different syntax than scatter(). It seems like you need to enter all the data at once, as vectors, and then use a grouping variable. Try this:
groups = repelem(1:numel(n), numel(z1)*numel(m));
scatterhist(reshape(permute(F1,[3 1 2]),[],1), reshape(permute(F2,[3 1 2]),[],1),...
'Group', groups(:),...
'Color', C);
1 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
Ole il 13 Lug 2020
Thank you!

Accedi per commentare.

Categorie

Scopri di più su Scatter Plots in Help Center e File Exchange

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by