How to create a good looking surface plot with inconsistent mesh size?
Afficher commentaires plus anciens
I have data that forms a 3-dimensional surface that was gathered with an inconsistent mesh size. NOTE: I've now edited this post so that the data file is attached and the image files showing my attempt at plots are shown below.
An inconsistent mesh size was used in order to examine fine details. I would like to create a nice looking surface plot (maybe using interpolation?) to include in a publication. You can locate my data file here: https://pastebin.com/tKTzLSkL. EDIT: The data file is now attached to this post. I've posted some images below, with descriptions of what I've tried, so that folks have a better idea of what I'm talking about and struggling with. Here's an image of what a scatter plot of my data looks like:

I'm pretty inexperienced with matlab and don't know what I'm doing. I've been able to create a plot in which a triangular mesh connects all of my data points, but the color scheme looks pretty ugly. It's certainly not something I'd put on a slide for a presentation, let alone in a publication.
Here's my attempt at a triangular mesh in matlab:

Here's the code I tried using to generate the triangular mesh plot (note: I stored my data in a matrix called 'largecomp'):
x=largecomp(:,1);
y=largecomp(:,2);
gridDelaunay=delaunay(x,y);
trisurf(gridDelaunay,x,y,z,'EdgeColor','none')
6 commentaires
John D'Errico
le 27 Juin 2017
Better to post your data than pictures that force us to go to another site. At least just attach a figure.
The surface itself is a bit of a mess though, essentially with what appear to be discontinuities in a few places, or at least immense gradients. I got that without even looking at the surface you tried to create. The point is, interpolation will still be a problem with those issues.
meslier1986
le 27 Juin 2017
Modifié(e) : meslier1986
le 27 Juin 2017
John D'Errico
le 27 Juin 2017
Thanks for inserting the pictures. That makes it easier to see, and so easier (ergo more likely) for you to get help. You can attach a .mat file using the paper clip icon. I'll take a look at the data.
John D'Errico
le 28 Juin 2017
Modifié(e) : John D'Errico
le 28 Juin 2017
OK, here is the surface generated from your data.

It should the roughly the same thing you generated, because I did a triangulation on (x,y), then created the surface using z in the third dimension.
The biggest difference in whatI did and what you did is I used z for the pseudo-coloring in the image.
What really matters is the angle I'm viewing the plot. Look at the stuff on the right. High spiky peaks, separated by small numbers.
There is also a lot of junk in those finely sampled areas on the left. I've left the black lines in the triangulation there, so you can visualize what is happening easily.
Interpolation techniques will just make it worse, because they will often generate overshoot (ringing) near those transients. And linear interpolation is exactly what you see here.
Others might suggest using my gridfit tool, downloaded from the file exchange. Don't bother. I know when I see something it will fail on. And of course you might get someone who suggests polynomial models. Run like hell away from that idea, as fast as you can in the other direction.
You can't make a silk purse from this sow's ear. This really is not a question of the inconsistent meshsize, but an issue of data that seems to be inconsistent. I don't know how you generated the data in those holes, but it is possible that a mistake was made.
meslier1986
le 28 Juin 2017
KSSV
le 28 Juin 2017
data = load('data.txt') ;
x = data(:,1) ; y = data(:,2) ; z = data(:,3) ;
tri = delaunay(x,y);
trisurf(tri,x,y,z) ;
Are you sure that your data is correct?
Réponses (1)
Benjamin Becker
le 28 Juin 2017
Modifié(e) : Benjamin Becker
le 28 Juin 2017
You could also have a look at the MATLAB function scatteredInterpolant. It does linear interpolation over a non-regular grid.
[x,y,z] = textread('data.txt','%f %f %f');
F = scatteredInterpolant(x,y,z,'linear','nearest');
x = linspace(min(x),max(x),200);
y = linspace(min(y),max(y),200);
[X,Y] = meshgrid(x,y);
Z = F(X,Y);
figure
mesh(X,Y,Z)
The figure then looks like this:

If you want to change the color take a look at the MATLAB function
colormap
As a first step it might be good to clean the data.
Catégories
En savoir plus sur Lighting, Transparency, and Shading dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!