简体   繁体   中英

increase the space between slices

I am trying to illustrate 2D matrices in 20 snapshots. I plotted it using slice but except the top matrix the rest can not be seen. Is there any way to increase the space between slices in order to be able to see each plane? Can also anyone suggest an alternative way to show the time evolution of a 4x8 matrix for t=1:20 ? Here is the tiny code I used to plot my data:

T2=20;
Xc = zeros(8,4,T2);
for j = 1:T2
    Xc(:,:,j) = mdp2(j).X{1};
end
hs = slice(Xc,[],[],1:T2) ;
lightangle(-45,45);
view([-25 30]);
xticks(linspace(0,20,41));
axis on;

How can I change ticks and label for axes here? 在此处输入图像描述 Thanks in advance

Your code with some random data:

T2=20;
Xc = zeros(8,4,T2);
for j = 1:T2
    Xc(:,:,j) = rand(8,4);
end
hs = slice(Xc,[],[],1:T2) ;
lightangle(-45,45);
view([-25 30]);
xticks(linspace(0,20,41));
axis on;

原始图像

As @CrisLuengo mentioned, here is the DataAspectRatio property as is (or use function daspect() , see here , to get this info):

h = gca;
h.DataAspectRatio
ans =

                         1          2.33333333333333          6.66666666666667
% Or use function daspect()

From MATLAB Documentation :

daspect([1 2 3]) specifies that the length of one unit along the x-axis equals the length of two units along the y-axis and three units along the z-axis.

Decreasing h.DataAspectRatio[3] increases slice gaps. eg:

set(h, 'DataAspectRatio', [1 2.333 2])

Makes the image like this:

带有扩展 Z 轴的图形

I would also add some transparency to make the data visible:

alpha(h, 0.7);

透明图

How can I change ticks and label for axes here

Use the axes property or function XTick , YTick , ZTick . Also, change the camera line of sight by view() like

xticks(1:4);
view(30, 20);

which gives:

改变了看法

EDIT 1 :

When using slice(Xc,[],[],1:T2) , it is assumed that Xc is a volume data with coordinates defined by the size of Xc . These coordinates follow grid representation which means the entire grid is defined by these coordinates. If your data represent the coordinates in between the grid points (which is the case here), then you should adjust for the missing data at the end of each dimension. So if I construct a binary random dataset with size 8 x 4 x 20 I have:

T2=20;
nRows = 8;
nCols = 4;
mdp2 = zeros(nRows, nCols, T2);
for j = 1:T2
    mdp2(:,:,j) = round(rand(nRows,nCols)); % Binary data
end

To make the grid size consistent, you should do something like this:

Xc = zeros(nRows+1,nCols+1,T2);
for j = 1:T2
    expan1 = [mdp2(:,:,j) mdp2(:,1,j)];
    Xc(:,:,j) = [expan1; expan1(1,:)];
end

Which then plots the entire data in Xc when doing

hs = slice(Xc,[],[],1:T2);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM