How do I plot a multivariate distribution?

조회 수: 2 (최근 30일)
Fabian Gock
Fabian Gock 2018년 8월 2일
답변: Pawel Jastrzebski 2018년 8월 6일
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

채택된 답변

Pawel Jastrzebski
Pawel Jastrzebski 2018년 8월 6일
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개)

카테고리

Help CenterFile Exchange에서 Descriptive Statistics and Visualization에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by