3

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.

Robert Seifert
  • 25,078
  • 11
  • 68
  • 113
Kelvin S
  • 341
  • 2
  • 4
  • 13
  • 1
    have a look at [`surf`](http://de.mathworks.com/help/matlab/ref/surf.html). Might do what you want. Just note that it will use volume data created with [`meshgrid`](http://de.mathworks.com/help/matlab/ref/meshgrid.html), so you may need to reformat the data before using it. The position of the color bar can be changed, using `pos = get (cb,'position');` and `set(cb,newpos);` – MinF Oct 05 '15 at 07:22
  • 1
    I have 3 answers to questions about plotting 4D data or cube-like stuff. Have a look to https://stackoverflow.com/questions/29229988/visualize-a-three-dimensional-array-like-cubic-lattice-using-matlab/29233108#29233108 , https://stackoverflow.com/questions/31828064/constructing-voxels-of-a-3d-cube-in-matlab/31829681#31829681 and https://stackoverflow.com/questions/27659632/reconstructing-three-dimensions-image-matlab/27660039#27660039 – Ander Biguri Oct 05 '15 at 08:12

1 Answers1

0

If the x and y are not uniform, i.e., with values at each grid intersection, you will not be able to cover the whole volume. You need to interpolate the input data.

Check "Surface Plots of Nonuniformly Sampled Data" example here.

hammadian
  • 323
  • 2
  • 9