How can I plot 3D contour plot for (x, y, z) Cartesian grid with values at each cell?
44 次查看(过去 30 天)
显示 更早的评论
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
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
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.
回答(6 个)
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 个评论
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
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
0 个评论
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.
0 个评论
Pavl M.
2024-11-7,13:32
编辑:Pavl M.
2024-11-7,14:15
You need to create suitable grid on your values loaded.
Please accept my solution:
(Works in NCE MPPL TCE Octave and Matlab):
clc
clear all
close all
% load your- x,y,z,v from file
%[x,y,z] = meshgrid(your_x,your_y,your_z);
%v = ndgrid(your_v)
%create detailed grid with next function
%Hattrell(2024). qgriddata (https://www.mathworks.com/matlabcentral/fileexchange/10399-qgriddata), MATLAB Central File Exchange. Extrait(e) le novembre 7, 2024.
GrdiSize = 1000;
dx = (yourxmax-yourxmin)/GridSize;
dy = (yourymax-yourymin)/GridSize;
dz = (yourzmax-yourzmin)/GridSize;
[x,y,z,v] = qgriddata(yourxmin,yourxmax,dx,yourymin,yourymax,dy,yourzmin,yourzmax,dz,yourx,youry,yourz,yourv);
step = dz;
zslice = yourzmin:step:yourzmax;
figure
h = slice(x,y,z,v,[],[],zslice,'spline');
colormap(turbo)
colorbar
set(h,'EdgeColor','none')
I run it in Octave on formula(equation) defined custom (works for any arbitrary function) and produced both slices and full 3D plot of field (function) values within a specified rectangular(cubic) region:
Should you need the exact running script code matter, more details for specific solutions service, contact me more in private.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Contour Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!