3D density plot - multiple isosurfaces on the same plot

50 views (last 30 days)
Greetings,
I am struggling to plot a 4D array (density at 3D space) and produce a plot like the attached image.
Actually it does not necessarily have to look like the attachment but it must present the data in a clear way. For that purpose I tried to use scatter3 and isosurface without any success. I am not sure if these functions are the right ones. Regarding scatter3(X,Y,Z,S), my problem is that S must be a vector of the same length as X,Y,Z, whereas I want it to be an size(X)*size(Y)*size(Z) array that contains the density values. On the other hand, I managed to draw a surface using:
p = patch(isosurface(x,y,z,density,2))
isonormals(x,y,z,density,p)
set(p,'FaceColor','blue','EdgeColor','none');
daspect([1,1,1])
view(3); axis tight
camlight
lighting gouraud
The produced plot looks like this:
Yet I didn't find how to draw multiple surfaces with increasing isovalue into the same plot and make them transparent. Is this possible in Matlab? If not is there any other function to plot a 4D array?
  1 Comment
Thomas
Thomas on 3 Jan 2014
This is hte best I could get with scatter3(X,Y,Z,S,'r','*'):
It is not obvious where the high density regions reside.
If anyone know how to create the first image using isosurface please give me some hints!

Sign in to comment.

Accepted Answer

Thomas
Thomas on 5 Jan 2014
I found it. This how I did the attached image:
figure
quantum=max(nfe)/8;
isovalue=6*quantum;
surf1=isosurface(x,y,z,normalized_Free_Energy_map,isovalue);
p1 = patch(surf1);
isonormals(x,y,z,normalized_Free_Energy_map,p1);
set(p1,'FaceColor','red','EdgeColor','none','FaceAlpha',0.1); % set the color, mesh and transparency level of the surface
daspect([1,1,1])
view(3); axis tight
camlight; lighting gouraud
isovalue=4*quantum;
surf2=isosurface(x,y,z,normalized_Free_Energy_map,isovalue);
p2 = patch(surf2);
isonormals(x,y,z,normalized_Free_Energy_map,p2);
set(p2,'FaceColor','yellow','EdgeColor','none','FaceAlpha',0.2);
isovalue=2*quantum;
surf3=isosurface(x,y,z,normalized_Free_Energy_map,isovalue);
p3 = patch(surf3);
isonormals(x,y,z,normalized_Free_Energy_map,p3);
set(p3,'FaceColor','cyan','EdgeColor','none','FaceAlpha',0.3);
isovalue=quantum;
surf4=isosurface(x,y,z,normalized_Free_Energy_map,isovalue);
p4 = patch(surf4);
isonormals(x,y,z,normalized_Free_Energy_map,p4);
set(p4,'FaceColor','blue','EdgeColor','none','FaceAlpha',1);
  4 Comments
Sakiru Badmos
Sakiru Badmos on 7 Feb 2017
Edited: Sakiru Badmos on 7 Feb 2017
Hi Thomas, I am having problem plotting my density data in the form of an isosurface. I have x,y,z and density data at each coordinate. I have tried isosurface function in Matlab but I got error as my density is a vector and not a matrix. Kindly help me out as I don't understand the input to your code. Is your normalized_free_energy_map a matrix or vector? What does quantum represent? Thank you

Sign in to comment.

More Answers (2)

Mechrod
Mechrod on 30 Jun 2017
Hi!
Instead of choosing the 'Facecolor', can Matlab use the values of the isosurfaces being plotted and create a colorbar based on this values?

R4pha3L
R4pha3L on 27 Feb 2017
Edited: Walter Roberson on 27 Feb 2017
To understand better how the input data works I've put together this small script:
%Isosurface test sript
clear all
close all
clc
x=1:3
y=1:5
z=1:4
[X,Y,Z]=meshgrid(x,y,z)
D = sqrt(X.^2+Y.^2+Z.^2)
max(D(:))
min(D(:))
figure
isovalue = 0.2*(max(D(:))-min(D(:)))+min(D(:))
surf1 = isosurface(X,Y,Z,D,isovalue)
p1 = patch(surf1);
isonormals(x,y,z,D,p1);
set(p1,'FaceColor','red','EdgeColor','none','FaceAlpha',0.1); % set the color, mesh and transparency level of the surface
daspect([1,1,1])
view(3);
camlight; lighting gouraud
isovalue = 0.4*(max(D(:))-min(D(:)))+min(D(:))
surf2=isosurface(x,y,z,D,isovalue);
p2 = patch(surf2);
isonormals(x,y,z,D,p2);
set(p2,'FaceColor','yellow','EdgeColor','none','FaceAlpha',0.2);
isovalue = 0.6*(max(D(:))-min(D(:)))+min(D(:))
surf3=isosurface(x,y,z,D,isovalue);
p3 = patch(surf3);
isonormals(x,y,z,D,p3);
set(p3,'FaceColor','cyan','EdgeColor','none','FaceAlpha',0.3);
isovalue = 0.8*(max(D(:))-min(D(:)))+min(D(:))
surf4=isosurface(x,y,z,D,isovalue);
p4 = patch(surf4);
isonormals(x,y,z,D,p4);
set(p4,'FaceColor','blue','EdgeColor','none','FaceAlpha',1);
%----------
The big differece in using isosurface() is that the input data has to be length(x) by length(y) by length(z) (in the example above 5x3x4 matrix) and even the density data has to have this format for it to work.
Hope this helps ;)

Community Treasure Hunt

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

Start Hunting!