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

14 visualizaciones (últimos 30 días)
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 comentarios
Ewen Chan
Ewen Chan el 28 de Jun. de 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 el 15 de Mzo. de 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.

Iniciar sesión para comentar.

Respuestas (5)

Sriram Narayanan
Sriram Narayanan el 3 de Jun. de 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 comentarios
Jia
Jia el 4 de Jun. de 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 el 1 de Abr. de 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

Iniciar sesión para comentar.


John A
John A el 22 de Nov. de 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 el 9 de Nov. de 2019
Anyone have got the required answers for the question of John A or Jia

Denis Perotto
Denis Perotto el 10 de Nov. de 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 el 5 de Mzo. de 2021
Did you try fill3. It might be what you need.

Categorías

Más información sobre Red en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by