Scatterplot equivalent in plotting 3d data in 2d

Hi everyone,
I have three vectors of same size (54796X1 double) and want to plot them like the image attached. Using the scatter function, scatter(x,y ,35, z, 'filled'), naturally I get a plot made of dots. I increased the dot size to make the data look full but as you can see it is not a good solution. Do you know how the plot in the attached image is generated with the same data? I thought of image but I can not get it to work. I have attached the vectors in the workspace. Here is how I got my plot using scatter and contour:
scatter(x,y ,35, z, 'filled')
x_interpolated = linspace( -90, 90, 300 );
y_interpolated = linspace( -90, 90, 300 );
[ hx, hy ] = meshgrid( x_interpolated, y_interpolated );
F = TriScatteredInterp(x, y, z);
data_interpolated = F(hx, hy);
hold on
contour( x_interpolated, y_interpolated, data_interpolated, 10, 'k' );
Any help is highly appreciated.
/Hasti

댓글 수: 6

KSSV
KSSV 2017년 7월 24일
Attach the data.....so that we can work on it and give a solution.
Those appear to be contour plots not scatter plots.
Scatter is not relevant here. You do not have hold on, so your entire plot is replaced by the contour plot derived from the scattered Interpolant
Hi walter, Thanks for fixing the code section in my question. I do have hold on and if you run scatter and contour separately you will see that they are two different plots.
It looks to me to be likely that your scatter plot is completely hidden by the contour plot. Both are in the z=0 plane and since they are the same depth and are both space filling areas instead of lines, the one that is going to show up is the one drawn last.
Hi Walter, I understand your concern but that is not the case here. I can not upload anymore images due to mathworks regulations but if you just run the contour and scatter function lines separately you will see my point.

댓글을 달려면 로그인하십시오.

 채택된 답변

KSSV
KSSV 2017년 7월 24일

0 개 추천

You need to do interpolation with the scattered data...and then use surf or pcolor. Read about scatteredInterpolant

댓글 수: 9

When I try your suggestion, I just get a mostly black plot. At which points do you calculated the z_interpolated? Here is my attempt:
F =scatteredInterpolant(phi_part, theta_part, data);
x_interpolated = linspace( -90, 90, 300 );
y_interpolated = linspace( -90, 90, 300 );
[hx, hy] = meshgrid( x_interpolated, y_interpolated );
data_interpolated = F(hx, hy);
surf(data_interpolated)
view([ 90 90 ]);
Add 'EdgeColor', 'none' to the surf call
Turning off the edge color takes away the black but it still does not give the plot I am looking for.
KSSV
KSSV 2017년 7월 24일
Try shading interp after surf
KSSV
KSSV 2017년 7월 24일
I already mentioned to attach the data....
KSSV
KSSV 2017년 7월 24일
편집: KSSV 2017년 7월 24일
load dataforplotting3din2d.mat ;
m = 500 ; n = 500 ;
x_interpolated = linspace( min(x), max(x),m);
y_interpolated = linspace(min(y),max(y),n); [ hx, hy ] = meshgrid( x_interpolated, y_interpolated );
F = TriScatteredInterp(x, y, z);
data_interpolated = F(hx, hy);
hold on
pcolor( x_interpolated, y_interpolated, data_interpolated);
shading interp
contour( x_interpolated, y_interpolated, data_interpolated, 30, 'k' );
I see! Thanks KSSV. So the solution was right in front me but I just didn't see it><
KSSV
KSSV 2017년 7월 24일
Yes....you were taking a small region out of the given region.
... and no scatter() plot.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Scatter Plots에 대해 자세히 알아보기

질문:

2017년 7월 24일

댓글:

2017년 7월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by