How do I plot a multivariate distribution?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Fabian Gock
am 2 Aug. 2018
Beantwortet: Pawel Jastrzebski
am 6 Aug. 2018
I have the efficiency map of an electric drive, in wich I plottet the operating points (torque at rpm) during a driving cycle.
Now I somehow want to display in wich areas the system is operating the most. So a multivariate distributional plot with peaks at the areas where the density of points is higher would be my wish.
Please find the attached file as an example (x-Axis is rpm, y-Axis is torque)
Thanks in advance -Fabian
1 Kommentar
Akzeptierte Antwort
Pawel Jastrzebski
am 6 Aug. 2018
Consider the following example:
NoOfPoints = 1000;
% Generate 'x' and 'y'
x = rand(NoOfPoints,1);
y = rand(NoOfPoints,1);
% 2d plot of the data
hFig(1) = figure;
hAx(1) = gca();
p(1) = scatter(...
hAx(1),...
x,...
y,...
'ro');
grid on
% generate histogram of the data
% this will give you the density of the points
hFig(2) = figure;
hAx(2) = gca();
NoOfBins = 10;
p(2) = histogram2(hAx(2),...
x,...
y,...
NoOfBins);
% extract peak value of every bin as well as it's
% 'x' and 'y' location
BinCenterX = p(2).XBinEdges(1:end-1) + diff(p(2).XBinEdges)/2;
BinCenterY = p(2).YBinEdges(1:end-1) + diff(p(2).YBinEdges)/2;
BinPeaks = p(2).Values;
% plot values from histogram as surface plot
hFig(3) = figure;
hAx(3) = gca();
p(3) = surface(hAx(3),...
BinCenterX,...
BinCenterY,...
BinPeaks,...
'EdgeAlpha',0.3,...
'FaceAlpha',0.4);
hold on
p(3) = scatter3(...
hAx(3),...
x,...
y,...
zeros(size(x)),...
'ro');
colorbar;
view(3)
grid on;
% use interpolation function to make the surface
% plot smoother
[meshX, meshY] = meshgrid(linspace(0,1,50));
BinPeaksInterp = interp2(...
BinCenterX,...
BinCenterY,...
BinPeaks,...
meshX,meshY,...
'cubic');
hFig(4) = figure;
hAx(4) = gca();
p(4) = surface(hAx(4) ,...
meshX,...
meshY,...
BinPeaksInterp,...
'EdgeAlpha',0.3,...
'FaceAlpha',0.4);
hold on
p(5) = scatter3(hAx(4),...
x,...
y,...
zeros(size(x)),...
'ro');
colorbar;
view(3)
grid on;
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Data Distribution Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!