필터 지우기
필터 지우기

colorbar scale is not correct when using isosurface and patch plots

조회 수: 5 (최근 30일)
Jamie Al
Jamie Al 2022년 12월 6일
댓글: Voss 2022년 12월 8일
Why is the color bar here giving me the values of the transparency "alpha" and not my data values that I am plotting?
Code:
Nx = 128;
Ny = 128;
Nz = 128;
Lx =128;
Ly = 128;
Lz = 128;
xi = (0:Nx-1)/Nx*2*pi;
xi_x = 2*pi/Lx;
x = xi/xi_x;
yi = (0:Ny-1)/Ny*2*pi;
yi_y = 2*pi/Ly;
y = yi/yi_y;
zi = (0:Nz-1)/Nz*2*pi;
zi_z = 2*pi/Lz;
z = zi/zi_z;
dx = Lx/Nx;
dy = Ly/Ny;
dz = Lz/Nz;
[X,Y,Z] = meshgrid(x,y,z);
%Sizing
fontSize = 16;
frames2Plot = [1 2 3 4 5 6];
numF = length(frames2Plot);
mB = 0.12;
mT = 0.05;
mL = 0.9;
sV = 0.005;
wC = 0.02;
sC = 0.02;
mC = 0.03;
mR = wC + sC + mC;
sH = 0.01;
sV = 0.01;
W = (1 - mL - mR - (numF/2-1)*sH) / (numF/2);
H = (1 - mT - mB - sV) / 2;
filelocation1 = 'C:\Users\Data\';
n = reshape(readmatrix([filelocation1,'Data',num2str(100),'.txt']),128,128,128);
Error using readmatrix
Unable to find or open 'C:\Users\Data\Data100.txt'. Check the path and filename or file permissions.
f = figure('Position',[14 63 851 600],'Renderer','Painters');
i = 1.5e11;
surf1 = isosurface(X,Y,Z,n,i);
p1 = patch(surf1);
isonormals(X,Y,Z,n,p1);
set(p1,'FaceColor','black','EdgeColor','none','FaceAlpha',0.1);
daspect([1,1,1])
view(3);
camlight; lighting gouraud
i = 2.5e11;
surf2 = isosurface(X,Y,Z,n,i);
p2 = patch(surf2);
isonormals(X,Y,Z,n,p2);
set(p2,'FaceColor','#7E2F8E','EdgeColor','none','FaceAlpha',0.2);
i = 3.5e11;
surf3 = isosurface(X,Y,Z,n,i);
p3 = patch(surf3);
isonormals(X,Y,Z,n,p3);
set(p3,'FaceColor','red','EdgeColor','none','FaceAlpha',0.3);
i = 4.5e11;
surf4 = isosurface(X,Y,Z,n,i);
p4 = patch(surf4);
isonormals(X,Y,Z,n,p4);
set(p4,'FaceColor','yellow','EdgeColor','none','FaceAlpha',1);
grid on;
xlabel('x(m)'); ylabel('y(m)'); zlabel('z(m)');
c = colorbar;
for i = 1:numF
hAxis(i).Position = [mL, (numF - i) * (sV + H) + mB , W, H];
end
c.Position = [mL + W + sC, mB, wC, 1 - mB - mT];
c.Label.String = 'values';
The color bar should be showing the value i and not "alpha", is there a way to fix this?? Thanks
  댓글 수: 3
Jamie Al
Jamie Al 2022년 12월 7일
I attached a zip file with one text file data. Now, if I don't use patch, just isosurface then my colorbar values are correct. Why is that?
figure;
i = 2.5e11;
isosurface(X,Y,Z,n,i);
alpha(0.0008)
hold on;
i = 3.5e11;
isosurface(X,Y,Z,n,i);
alpha(0.2)
hold on;
i = 4.5e11;
isosurface(X,Y,Z,n,i);
view(3)
colorbar;
Voss
Voss 2022년 12월 8일
unzip('ne231.zip')
Nx = 128;
Ny = 128;
Nz = 128;
Lx =128;
Ly = 128;
Lz = 128;
xi = (0:Nx-1)/Nx*2*pi;
xi_x = 2*pi/Lx;
x = xi/xi_x;
yi = (0:Ny-1)/Ny*2*pi;
yi_y = 2*pi/Ly;
y = yi/yi_y;
zi = (0:Nz-1)/Nz*2*pi;
zi_z = 2*pi/Lz;
z = zi/zi_z;
dx = Lx/Nx;
dy = Ly/Ny;
dz = Lz/Nz;
[X,Y,Z] = meshgrid(x,y,z);
%Sizing
fontSize = 16;
frames2Plot = [1 2 3 4 5 6];
numF = length(frames2Plot);
mB = 0.12;
mT = 0.05;
mL = 0.9;
sV = 0.005;
wC = 0.02;
sC = 0.02;
mC = 0.03;
mR = wC + sC + mC;
sH = 0.01;
sV = 0.01;
W = (1 - mL - mR - (numF/2-1)*sH) / (numF/2);
H = (1 - mT - mB - sV) / 2;
n = reshape(readmatrix('ne231.txt'),128,128,128);
f = figure('Position',[14 63 851 600],'Renderer','Painters');
i = 2.5e11;
isosurface(X,Y,Z,n,i);
alpha(0.0008)
hold on;
i = 3.5e11;
isosurface(X,Y,Z,n,i);
alpha(0.2)
hold on;
i = 4.5e11;
isosurface(X,Y,Z,n,i);
view(3)
colorbar;

댓글을 달려면 로그인하십시오.

답변 (1개)

Voss
Voss 2022년 12월 8일
Is this how it should be?
unzip('ne231.zip')
Nx = 128;
Ny = 128;
Nz = 128;
Lx =128;
Ly = 128;
Lz = 128;
xi = (0:Nx-1)/Nx*2*pi;
xi_x = 2*pi/Lx;
x = xi/xi_x;
yi = (0:Ny-1)/Ny*2*pi;
yi_y = 2*pi/Ly;
y = yi/yi_y;
zi = (0:Nz-1)/Nz*2*pi;
zi_z = 2*pi/Lz;
z = zi/zi_z;
dx = Lx/Nx;
dy = Ly/Ny;
dz = Lz/Nz;
[X,Y,Z] = meshgrid(x,y,z);
%Sizing
fontSize = 16;
frames2Plot = [1 2 3 4 5 6];
numF = length(frames2Plot);
mB = 0.12;
mT = 0.05;
mL = 0.9;
sV = 0.005;
wC = 0.02;
sC = 0.02;
mC = 0.03;
mR = wC + sC + mC;
sH = 0.01;
sV = 0.01;
W = (1 - mL - mR - (numF/2-1)*sH) / (numF/2);
H = (1 - mT - mB - sV) / 2;
cmap = [ ...
0 0 0; ... 'black'
126 47 142; ... '#7E2F8E'
255 0 0; ... 'red'
255 255 0; ... 'yellow'
]/255;
% filelocation1 = 'C:\Users\Data\';
n = reshape(readmatrix('ne231.txt'),128,128,128);
f = figure('Position',[14 63 851 600],'Renderer','Painters');
i = 1.5e11;
surf1 = isosurface(X,Y,Z,n,i);
p1 = patch(surf1);
isonormals(X,Y,Z,n,p1);
set(p1,'FaceColor',cmap(1,:),'EdgeColor','none','FaceAlpha',0.1);
daspect([1,1,1])
view(3);
camlight; lighting gouraud
i = 2.5e11;
surf2 = isosurface(X,Y,Z,n,i);
p2 = patch(surf2);
isonormals(X,Y,Z,n,p2);
set(p2,'FaceColor',cmap(2,:),'EdgeColor','none','FaceAlpha',0.2);
i = 3.5e11;
surf3 = isosurface(X,Y,Z,n,i);
p3 = patch(surf3);
isonormals(X,Y,Z,n,p3);
set(p3,'FaceColor',cmap(3,:),'EdgeColor','none','FaceAlpha',0.3);
i = 4.5e11;
surf4 = isosurface(X,Y,Z,n,i);
p4 = patch(surf4);
isonormals(X,Y,Z,n,p4);
set(p4,'FaceColor',cmap(4,:),'EdgeColor','none','FaceAlpha',1);
grid on;
xlabel('x(m)'); ylabel('y(m)'); zlabel('z(m)');
c = colorbar;
colormap(cmap)
n_colors = size(cmap,1);
caxis([1 n_colors+1]*1e11);
c.YTick = ((1:n_colors)+0.5)*1e11;
for i = 1:numF
hAxis(i).Position = [mL, (numF - i) * (sV + H) + mB , W, H];
end
c.Position = [mL + W + sC, mB, wC, 1 - mB - mT];
c.Label.String = 'values';

카테고리

Help CenterFile Exchange에서 Scalar Volume Data에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by