필터 지우기
필터 지우기

How to change the marking in colorbar?

조회 수: 17 (최근 30일)
Athira T Das
Athira T Das 2023년 4월 20일
답변: Walter Roberson 2023년 4월 20일
How to change the colorbar marking uniformly?
clc;close all;clear all;
lambda=532
lambda = 532
w0 = 1; % beam waist
z = 0; % propagation distance
k = 2*pi/lambda; % wave number
l = 1; % topological charge
x = linspace(-5*w0,5*w0,256); % x-axis grid
y = linspace(-5*w0,5*w0,256); % y-axis grid
[X,Y] = meshgrid(x,y); % create meshgrid
R = sqrt(X.^2 + Y.^2);
phi = atan2(Y,X) + l*atan2(R,z);
u = exp(-(X.^2 + Y.^2)/w0^2) .* exp(1i*phi);
figure;
imagesc(x,y,angle(u));
colormap('hsv');
axis equal tight;
xlabel('x');
ylabel('y');
cb = colorbar;
cb.Ticks = [0 0.5 1];
cb.TickLabels = {'0', 'pi/2', '2pi'};

채택된 답변

Walter Roberson
Walter Roberson 2023년 4월 20일
lambda=532
lambda = 532
w0 = 1; % beam waist
z = 0; % propagation distance
k = 2*pi/lambda; % wave number
l = 1; % topological charge
x = linspace(-5*w0,5*w0,256); % x-axis grid
y = linspace(-5*w0,5*w0,256); % y-axis grid
[X,Y] = meshgrid(x,y); % create meshgrid
R = sqrt(X.^2 + Y.^2);
phi = atan2(Y,X) + l*atan2(R,z);
u = exp(-(X.^2 + Y.^2)/w0^2) .* exp(1i*phi);
figure;
angu = angle(u);
imagesc(x,y,angu);
colormap('hsv');
axis equal tight;
xlabel('x');
ylabel('y');
caxis
ans = 1×2
-3.1377 3.1377
[min(angu(:)), max(angu(:))]
ans = 1×2
-3.1377 3.1377
cb = colorbar;
cb.Ticks = [0 0.5 1];
cb.TickLabels = {'0', 'pi/2', '2pi'};
Your actual data being drawn ranges from pretty much to . imagesc() leaves the data alone but changes the CLim (color axes limits) to match the actual range of data. You then ask for tick marks at the absolute positions 0, 0.5, and 1, rather than at some kind of relative position.
You also label with 0 to even though the values are to
I would suggest that what you want is
w0 = 1; % beam waist
z = 0; % propagation distance
k = 2*pi/lambda; % wave number
l = 1; % topological charge
x = linspace(-5*w0,5*w0,256); % x-axis grid
y = linspace(-5*w0,5*w0,256); % y-axis grid
[X,Y] = meshgrid(x,y); % create meshgrid
R = sqrt(X.^2 + Y.^2);
phi = atan2(Y,X) + l*atan2(R,z);
u = exp(-(X.^2 + Y.^2)/w0^2) .* exp(1i*phi);
figure;
angu = angle(u);
imagesc(x,y,angu);
colormap('hsv');
axis equal tight;
xlabel('x');
ylabel('y');
caxis([-pi pi])
cb = colorbar;
cb.Ticks = [-pi 0 pi];
cb.TickLabels = {'-\pi', '0', '\pi'};

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by