how to draw 2D or 3D graphs with large data

I have a data that contains X and Y coordinates (almost 25000 each), I also have Z values from an experiments. I would like to draw a 3D graph or 2D that can plot X and Y coordinates while Z coresponds to the height/density or just color at each X and Y values. I have tried to reduce my data to 400 and used the below
z=repmat(Z,1,400);
Figure
Surf(X,Y,z)
shading interp
colorbar
view ([0 90])
axis('equal')
However, the figure wasn't understandable and it was showing a square unlike the real data even when I use only the 400 it suppose to be like a (+) not square.
I have also tried the meshgrid for X and Y and repmat for Z but the result was almost the same.
I'm looking for something simillar to the attached figure.
Is there anyway that I can do that knowing that all my data are known (no equations or assumptions needed)

2 Comments

%if true
% code
% end
h = figure
...
surf...
ax = axes('Parent',h)
view(ax,[0 90])
%axis('equal')!
Thank you for your answer, I'm a beginner, can you please give me more details or what to do exactly?
consider my variables names X,Y, Z and table name T.
Thanks again

Sign in to comment.

 Accepted Answer

Let (x,y,z) be your column data.
dt = delaunayTriangulation(x,y) ;
tri = dt.ConnectivityList ;
figure
trisurf(tri,x,y,z)
shading interp

10 Comments

Thank you KSSV, the resulted figure had the shape of diamond (the points in the south connected with the points in the east and west) while my final shape should be ( + ). Therefore is there any other way to make it look closer to a (+), please note that I don't have to use surf, its fine with me to use lines, histograms or anything that can show Z as height or color.
Okay..I got the problem ...attach your data...
Try this:
num = xlsread("90.xlsx") ;
x = num(:,1) ;
y = num(:,2) ;
z = num(:,3) ;
x0 = min(x) ; x1 = max(x) ;
y0 = min(y) ; y1 = max(y) ;
xi = linspace(x0,x1,500) ;
yi = linspace(y0,y1,500) ;
[X,Y] = meshgrid(xi,yi) ;
Z = griddata(x,y,z,X,Y) ;
pcolor(X,Y,Z)
shading interp
If the above does not give proper result. Try the below
% Get boundary coordinates
idx = boundary(x,y) ;
xb = x(idx) ; yb = y(idx) ;
% Get points lying inside the boundary
idx = inpolygon(X,Y,xb,yb) ;
Z(~idx) = NaN ;
pcolor(X,Y,Z)
shading interp
the second code gave the exact opposite result, it has deleted the middle area and kept the outside (see attached), thus if the result can be flipped it would give the proper result.
I have made a small change in the second code....use ~idx instead of idx...now try.
well, I got the graph now but all with the same color as if its only X and Y
I think its because of this warning
> In griddata>useScatteredInterp (line 181)
In griddata (line 122)
Thre might be few outliers....most of the values are within 400, only 10 values are greater than 400. Remove these outliers and see.
Also try refining the grid..I have used 500, you make it a fine grid.
Thank you very much, that was very helpful

Sign in to comment.

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Products

Tags

Community Treasure Hunt

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

Start Hunting!