Plotting 3D surface contours of a variable with respect to x, y and z
3 views (last 30 days)
Show older comments
I am trying to plot a 3D surface contour plot a varaible (dust mixing ratio) with respect to lat (x-axis), long (y-axis) and levels (z axis) (attached csv file). But I am unable to plot that. While making the meshgrid I am getting an error Requested 248040x248040x2 (916.8GB) array exceeds maximum array size preference. How to plot this?
2 Comments
Rik
on 12 Jun 2023
What code did you try? You can put it right in your question and run the code to show us exactly how to reproduce the error.
And what do you want exactly? A surface plot or a contour plot? Both rely on a single value for the height given an x-y coordinate pair. Your error suggests you have a list of coordinates that should be reshaped instead of using meshgrid.
Answers (2)
Rik
on 12 Jun 2023
It sounds like you want a 3D pointcloud where the color represents a 4th variable.
As you can see below, this might not actually be a very informative plot.
t = tic;%keep track of time
unzip('MIXING_RATIOe.zip')
T=readtable('MIXING_RATIOe.csv');
lat = T.lat;
lev = T.levels;
lon = T.lon;
values = T.dust_mixing_ratio;
cmap = colormap('parula');
N_colors = size(cmap,1);
unique_values = unique(values);
C_ax = [min(values) , max(values)];
N = numel(unique_values);
%for n=1:N
for n=randperm(N) % this is to make sure stopping halfway doesn't distort the plotted colors
L = values == unique_values(n);
col_idx = interp1(...
linspace(C_ax(1),C_ax(2),N_colors),... % data range
1:N_colors,... % colormap indices available
unique_values(n)); % query current value
plot3(lat(L),lon(L),lev(L),...
'.','color',ind2rgb_private(col_idx,cmap))
if n==1,hold('on'),elseif n==N,hold('off'),end
% for the online environment, exit after 20 seconds of work
if toc(t)>20,break,end,hold('on')
end
colorbar,caxis(C_ax) % add colorbar and adjust limits to match the plotted results
function col = ind2rgb_private(col_idx,cmap)
% extend ind2rgb to allow decimal indices
N_colors = size(cmap,1);
col = [...
interp1(1:N_colors,cmap(:,1),col_idx),...
interp1(1:N_colors,cmap(:,2),col_idx),...
interp1(1:N_colors,cmap(:,3),col_idx)];
end
4 Comments
Rik
on 12 Jun 2023
I suspect you could get something like this if you set the Alpha property of a patch object below a certain threshold (and scale that with the value as well).
I don't know how fine your slices need to be before you don't notice them anymore. I suggest you give it a try. I'm not aware of any way to create this using solid voxels in Matlab.
shravani banerjee
on 22 Jun 2023
Edited: shravani banerjee
on 22 Jun 2023
1 Comment
Rik
on 22 Jun 2023
Can you provide a link? I can't find it on Google, so I doubt it will be easy to find for future readers of this thread.
See Also
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!