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

조회 수: 16 (최근 30일)
Jia
Jia 2015년 6월 1일
답변: Mingta Yang 2021년 3월 5일
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
Ewen Chan
Ewen Chan 2017년 6월 28일
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 2019년 3월 15일
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.

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

답변 (5개)

Sriram Narayanan
Sriram Narayanan 2015년 6월 3일
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
Jia
Jia 2015년 6월 4일
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 2020년 4월 1일
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

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


John A
John A 2017년 11월 22일
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 2019년 11월 9일
Anyone have got the required answers for the question of John A or Jia

Denis Perotto
Denis Perotto 2019년 11월 10일
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 2021년 3월 5일
Did you try fill3. It might be what you need.

카테고리

Help CenterFile Exchange에서 Red에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by