Graphics from 2D data
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
Hi there,
I have a matrix x of size 39505X2 and i was wondering how can i plot graphics as shown below from my data

채택된 답변
Star Strider
2023년 9월 26일
0 개 추천
It would be nice to have ‘x’ since I suspect that ‘x(:,1)’ cycliically repeats. Using reshape to use the cyclic repeat information to create a matrix from ‘x(:,2)’ could be the solution.
댓글 수: 8
Weather502
2023년 9월 26일
편집: Torsten
2023년 9월 26일
xy = load("x y data.mat")
xy = struct with fields:
all_data: [39505×2 double]
xy.all_data
ans = 39505×2
0.4534 0.5567
0.4534 0.6945
0.3485 0.6043
0.3591 0.6032
0.4371 0.5032
0.4418 0.5032
0.4418 0.4861
0.3958 0.4764
0.3873 0.4693
0.3873 0.4764
My data is very random and i have attached in
Torsten
2023년 9월 26일
So you have x/y data. And where are the z-data your colour plot is based on: z = f(x,y) ?
Oh well. So much for that idea.
There are duplicated values, however they are in no regular pattern. It is likely not possible to construct anything of significance from these data. I have no idea where the matrix in the plot came from, however it was not from these data.
LD = load('x y data.mat')
LD = struct with fields:
all_data: [39505×2 double]
Data = LD.all_data
Data = 39505×2
0.4534 0.5567
0.4534 0.6945
0.3485 0.6043
0.3591 0.6032
0.4371 0.5032
0.4418 0.5032
0.4418 0.4861
0.3958 0.4764
0.3873 0.4693
0.3873 0.4764
x = Data(:,1);
y = Data(:,2);
[Ux,~,ixx] = unique(x,'stable');
Xcounts = accumarray(ixx, (1:numel(ixx)).', [], @(x){x});
% [MaxSizeX,idxx] = maxk(cellfun(@numel, Xcounts),5)
[Uy,~,ixy] = unique(y,'stable');
Ycounts = accumarray(ixy, (1:numel(ixy)).', [], @(x){x});
% [MaxSizeY,idxy] = maxk(cellfun(@numel, Ycounts),5)
figure
scatter(x, y, 5, exp(-(x-mean(x)).^2 .* (y-mean(y)).^2), '.')
colormap(turbo)
colorbar
axis('equal')

I can get this far, however I cannot figure out how to get what appears to be an imagesc plot from it.
.
I wonder if it is a density plot?
xy = load("x y data.mat")
xy = struct with fields:
all_data: [39505×2 double]
x = xy.all_data(:,1);
y = xy.all_data(:,2);
scatter(x, y)

No. density doesn't seem to match example plot.
Weather502
2023년 9월 26일
편집: Weather502
2023년 9월 26일
probably i am looking some kind of density plot ot contour map to visualize my data.
Thanks
I experimented a bit more with this.
Here are some options —
LD = load('x y data.mat');
Data = LD.all_data
Data = 39505×2
0.4534 0.5567
0.4534 0.6945
0.3485 0.6043
0.3591 0.6032
0.4371 0.5032
0.4418 0.5032
0.4418 0.4861
0.3958 0.4764
0.3873 0.4693
0.3873 0.4764
x = Data(:,1);
y = Data(:,2);
[Ux,~,ixx] = unique(x,'stable');
Xcounts = accumarray(ixx, (1:numel(ixx)).', [], @(x){x});
% [MaxSizeX,idxx] = maxk(cellfun(@numel, Xcounts),5)
[Uy,~,ixy] = unique(y,'stable');
Ycounts = accumarray(ixy, (1:numel(ixy)).', [], @(x){x});
% [MaxSizeY,idxy] = maxk(cellfun(@numel, Ycounts),5)
SF = 3E+2; % Scalle Factor (For Gaussian Approximation)
z = exp(-(x-mean(x)).^2*SF) .* exp(-(y-mean(y)).^2*SF);
% figure
% plot(x, exp(-(x-mean(x)).^2*SF))
% hold on
% plot(y, exp(-(y-mean(y)).^2*SF))
% hold off
figure
scatter(x, y, 5, z, '.')
colormap(turbo)
colorbar
axis('equal')

figure
% stem3(x, y, z, '.')
hold on
scatter3(x, y, z, 2.5, z, 'o', 'filled')
hold off
colormap(turbo)
colorbar
xlabel('X')
ylabel('Y')
zlabel('Density')
grid on
view(-37.5,30)

% axis('equal')
xv = linspace(min(x), max(x), fix(sqrt(numel(x))));
yv = linspace(min(y), max(y), fix(sqrt(numel(y))));
F = scatteredInterpolant(x, y, z);
Warning: Duplicate data points have been detected and removed - corresponding values have been averaged.
[X,Y] = ndgrid(xv, yv);
Z = F(X,Y);
figure
surfc(X, Y, Z, 'EdgeColor','interp')
colormap(turbo)
colorbar
xlabel('X')
ylabel('Y')
zlabel('Density')

% [az,el] = view
[Uxy,~,ix] = unique(Data,'rows','stable');
Tally = accumarray(ix, (1:numel(ix)), [], @(x){Data(x,:)});
Density = cellfun(@(x)size(x,1), Tally);
figure
scatter3(Uxy(:,1), Uxy(:,2), Density, 5, Density, 'o', 'filled')
colormap(turbo)
colorbar
xlabel('X')
ylabel('Y')
zlabel('Density')
title('Empirical Density Plot')

figure
hist3(Data,[250 250],'CDataMode','auto','FaceColor','interp')
colormap(turbo)
colorbar
xlabel('X')
ylabel('Y')
zlabel('Density')
title('Empirical Density Histogram Plot')

[N,C] = hist3(Data,[250 250]);
figure
imagesc(C{1}, C{2}, N)
colormap(turbo)
colorbar
set(gca, 'YDir','normal')
xlabel('X')
ylabel('Y')
title('Image Plot Of Density Data')

The accumarray call that produced the density data for the final plot is the best I can do with an empirical approximation of the density. It counts the numbers of (x,y) pairs with the same coordinates, as determined by the last unique call. It might be possible to do a nonlinear fit of the hist3 results to a bivariate Gaussian distribution.
.
Weather502
2023년 9월 29일
Thank you @Star Strider
Star Strider
2023년 9월 29일
편집: Star Strider
2023년 9월 29일
As always, my pleasure!
EDIT — (29 Sep 2023 at 17:48)
Just out of interest —
LD = load('x y data.mat');
Data = LD.all_data;
x = Data(:,1);
y = Data(:,2);
zfcn = @(b,xy) b(1).*exp(-(xy(:,:,1)-b(2)).^2*b(3)) .* exp(-(xy(:,:,2)-b(4)).^2*b(5));
[N,C] = hist3(Data,[250 250]);
xv = linspace(min(x), max(x), size(N,1));
yv = linspace(min(y), max(y), size(N,2));
[X,Y] = ndgrid(xv, yv);
XY = cat(3, X, Y);
B = lsqcurvefit(zfcn,[50,mean(x),300,mean(y),300],XY,N)
Local minimum possible.
lsqcurvefit stopped because the final change in the sum of squares relative to
its initial value is less than the value of the function tolerance.
B = 1×5
31.5122 0.3762 771.2200 0.5087 335.3531
ZZ = zfcn(B,XY);
figure
surf(X, Y, N, 'EdgeColor',[1 1 1]*0.5, 'FaceAlpha',0.25, 'EdgeAlpha',0.25)
hold on
surf(X,Y,ZZ, 'EdgeColor','interp')
hold off
colormap(turbo)
colorbar
xlabel('X')
ylabel('Y')

.
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
