How can I plot 3D contour plot for (x, y, z) Cartesian grid with values at each cell?

8 vues (au cours des 30 derniers jours)
Jia
Jia le 1 Juin 2015
What code should I use to plot a 3D contour plot? I saw there are some contour3 functions, but I don't know how to create the 2*2 matrix for my data. I have data include (x,y,z) positioning data and value at each position. I attached part of my data looks like, not all y,z values are zero.
I also attached a plot that shows closely to what I want, but I also want scales shown on the figure.
  2 commentaires
Ewen Chan
Ewen Chan le 28 Juin 2017
I have a very similar problem where I have x, y, z, w data and I want to create a contour plot with that (please see attached text file).
I tested out Sriram's answer below, but it only gives me a contour plot of a slice of data, but not necessarily the whole thing, so I am wondering if someone can please help me plot my entire data set.
Thank you.
Denis Perotto
Denis Perotto le 15 Mar 2019
I have a similar problem. Seems like that is not possible at all. All I managed to do is to cycle a 'fill3' function to build a contour from several rectangles, but it cost a lot of RAM and lags.

Connectez-vous pour commenter.

Réponses (5)

Sriram Narayanan
Sriram Narayanan le 3 Juin 2015
Since you have values at points (x,y,z) in space, you could use the 3-D interpolation function "interp3" to interpolate between the points from the sample data and then use the "surf" function to generate the 3-D plot and the colorbar command to add the scale.
The following page talks about how to use this function.
Example code is:
generatedvalues = @(X,Y,Z)(X.^2 + Y.^3 + Z.^4);
[X,Y,Z] = meshgrid((-5:.25:5));
V = generatedvalues(X,Y,Z);
x = X(:,3,:);
y = Y(:,3,:);
z = V(:,3,:);
v = V(:,3,:);
z = Z(:,3,:);
x = squeeze(x);
y = squeeze(y);
z = squeeze(z);
v = squeeze(v);
surf(x,y,z);
colorbar
  2 commentaires
Jia
Jia le 4 Juin 2015
Thank you so much for your help. Now, I know how to define the grid, but how can I color these grid cells with my list of "V" values?
Luca Greggio
Luca Greggio le 1 Avr 2020
maybe i have got the answer
close all
clear all
file = fopen('valori.dat');
imax = fscanf(file, '%d \n', 1);
x = fscanf(file, '%f \n', imax);
y = fscanf(file, '%f \n', imax);
z = fscanf(file, '%f \n', imax);
T = fscanf(file, '%f \n', imax^3);
T = reshape(T,[imax, imax, imax]);
[X,Y,Z]=meshgrid(x,y,z);
xs = squeeze(X(:,7,:));
ys = squeeze(Y(:,7,:));
zs = squeeze(Z(:,7,:));
surf(xs,ys,zs,squeeze(T(:,:,7)));
colorbar
this get data from the file 'valori.txt' and when i apply the procedure in the answer, i simply add the 4th value in surf which is C, standing for color, this give the opportunity to give a color to the grid from your V value, in my case is T, i am plotting a 3D Heat equation soulution, i hope this can help

Connectez-vous pour commenter.


John A
John A le 22 Nov 2017
I have 5 surfaces, each is a 5 by 10 matrix. Each entry represents force value and is 1inch from neighboring entries on the surface. I was hoping to stack these surfaces to create a 3D block and contour (or color code) the block based on the magnitudes of these value. The expected outcome will be a block similar to Jia's block model shown above. Can someone please direct me on how to do this in matlab? I am a beginner in matlab but can find my way out if pointed in the right direction.
Thank you

Kabilan K
Kabilan K le 9 Nov 2019
Anyone have got the required answers for the question of John A or Jia

Denis Perotto
Denis Perotto le 10 Nov 2019
Download free Paraview (visualization tool) from https://www.paraview.org/download/. It will cost you some time to deal with VTK files, but anyway, MATLAB is not a tool for 3D contour visualization.

Mingta Yang
Mingta Yang le 5 Mar 2021
Did you try fill3. It might be what you need.

Catégories

En savoir plus sur Red dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by