MATLAB 4D color plot
5 次查看(过去 30 天)
显示 更早的评论
I am an amateur user of MATLAB and I would like to have a 4D color plot which the color represent the forth dimension. I try to use scatter3 as follow:
fid = fopen('abc.dat','r');
datacell = textscan(fid, '%f%f%f%f');
fclose(fid);
all_data = cell2mat(datacell); %converted into a matrix
boxx = all_data(:,1);
boxy = all_data(:,2);
boxz = all_data(:,3);
disden = all_data(:,4); %color depends on the value of disden
scatter3(boxx,boxy,boxz,400,disden,'filled')
xlabel('Box x')
ylabel('Box y')
zlabel('Box z')
cb = colorbar; % create the colorbar
set(get(cb,'title'),'string','Dislocation Density(m^{-2})'); % label colobar
Although it works but I want the whole space to be filled up by cubes instead of spots in the above case. In the above case only spots are used so even their size can be set they still cannot fill up the space. All my x,y,z values are integers, can I use cube with size 1x1x1 with colors defined by the forth dimension so that the whole space can be filled up?
Another problem is the label of the color bar is too close with the numbers shown in colorbar and they overlap. Can I set the position of the bar label so that it is a little bit further away?
Many thanks.
0 个评论
回答(1 个)
Walter Roberson
2015-10-5
scatter3() cannot create cubes. You can create cubes using patch().
Caution: when you fill up the space with cubes, you will not be able to see "into" the space, except to the extent that you use AlphaData to make surfaces more or less transparent.
When you have solid 3D (plus value) data then you should consider a voxel viewer, or slice() or isosurface()
2 个评论
Walter Roberson
2015-10-5
patch() has a calling sequence which is not the same as scatter3(). See http://www.mathworks.com/help/matlab/ref/patch.html
In particular in order to create the cubes like you want, you will want to use the Faces and Vertices form, along with passing some of the other properties which you can find described at http://www.mathworks.com/help/matlab/ref/patch-properties.html
You will need to decide whether you want to build interior cubes or if you just want to define a bunch of rectangular faces. Either way watch out for defining the vertices in a consistent order so that lighting can be done correctly.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!