How to rotate domain, but the lon and lat are on the contour (not on the axis)

조회 수: 8 (최근 30일)
Dear all, as far we know Matlab will traditionally generate 4 white areas when using the following script on rotate domain:
figure;
p=pcolor(lon_rho,lat_rho,h2a);shading interp;
An example illustration is attached. Instead of generating a map like the illustration, I want the lon and lat to be directly placed on the generated contour, note the black numbers in the attachment (not on the matlab x and y axis). Is this possible?
and this is a perfect example of what I want to get:
  댓글 수: 2
Dyuman Joshi
Dyuman Joshi 2025년 6월 28일
이동: Dyuman Joshi 2025년 6월 29일
You can try something like this as showed in this thread.
Note that the aspect ratio of axes will get distorted as per the angle, so adjust them as per your requirement.
X = [1 2 3; 1 2 3; 1 2 3];
Y = X';
C = [3 4 5; 1 2 5; 5 5 5];
%Default orientation
pcolor(X,Y,C)
%Modified orientation
figure
axes
%rotate camera about viewing axis
camroll(30)
xlabel('X')
ylabel('Y')
%set(gca,'dataaspectratiomode','manual')
hold all
pcolor(X,Y,C)
As to why the ylabel moves to the right side, I do not know yet.
eko supriyadi
eko supriyadi 2025년 6월 28일
이동: Dyuman Joshi 2025년 6월 29일
Thanks for the help Joshi, unfortunately that's not what I wanted. Because from the example of X, Y, and Z that you gave, it is basically not a rotation domain. Here are the variables I'm referring to (see attachment)
load rotate.mat
figure;
p=pcolor(lon_rho,lat_rho,z);shading interp;
and will result in a rotating domain like this:
I want the result to be Lon and Lat attached to the side of the contour (black box) instead of the conventional x and y-axis. How to do this in matlab?

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

채택된 답변

Walter Roberson
Walter Roberson 2025년 6월 28일
편집: Walter Roberson 2025년 6월 28일
You need to first calculate the tilt angle of the valid part of the data, then rotate by the negative of that angle so that the valid part would lie along the x axis. Then draw that, and camorbit() the resulting graph to tilt the plotted axes back to the original angle.
  댓글 수: 2
eko supriyadi
eko supriyadi 2025년 6월 29일
편집: eko supriyadi 2025년 6월 29일
Tks Walter, now I've been able to solve this problem, here's a script that might be useful for others:
% Rotational Transformation
tick_len = 0.055;
x = lon_rho;
y = lat_rho;
theta = median(angle(:)); % take the main angle of the domain
X_rot = cos(-theta)*(x - mean(x(:))) - sin(-theta)*(y - mean(y(:)));
Y_rot = sin(-theta)*(x - mean(x(:))) + cos(-theta)*(y - mean(y(:)));
% Data Plot on Rotated Grid
figure;
p = pcolor(X_rot, Y_rot, h); shading interp
hold on
axis off
% Add Manual Labels (lon/lat) at domain edge contour positions
% take 4 sides
[ny, nx] = size(lon_rho);
side_pts = {
[1:nx; ones(1,nx)], % top side
%[1:nx; ny*ones(1,nx)], % bottom side
%[ones(1,ny); 1:ny], % left side
%[nx*ones(1,ny); 1:ny] % right side
};
for k = 1:length(side_pts)
idx = sub2ind(size(lon_rho), side_pts{k}(2,:), side_pts{k}(1,:));
lon_labels = lon_rho(idx);
lat_labels = lat_rho(idx);
Xl = cos(-theta)*(lon_labels - mean(x(:))) - sin(-theta)*(lat_labels - mean(y(:)));
Yl = sin(-theta)*(lon_labels - mean(x(:))) + cos(-theta)*(lat_labels - mean(y(:)));
for i = 1:round(length(Xl)/8):length(Xl)
text(Xl(i), Yl(i)-0.1, sprintf('%.1f°E', lon_labels(i)), ...
'Color','k','FontSize',12,'FontWeight','bold', ...
'Rotation',0, 'HorizontalAlignment','center');
%make tick
lon_tick = lon_rho(1, i);
lat_tick = lat_rho(1, i);
x1 = cos(-theta)*(lon_tick - mean(x(:))) - sin(-theta)*(lat_tick - mean(y(:)));
y1 = sin(-theta)*(lon_tick - mean(x(:))) + cos(-theta)*(lat_tick - mean(y(:)));
plot([x1 x1], [y1 y1 - tick_len], 'k', 'LineWidth', 1);
%make grid
lon_line = lon_rho(:,i);
lat_line = lat_rho(:,i);
xg = cos(-theta)*(lon_line - mean(x(:))) - sin(-theta)*(lat_line - mean(y(:)));
yg = sin(-theta)*(lon_line - mean(x(:))) + cos(-theta)*(lat_line - mean(y(:)));
plot(xg, yg, 'k--', 'LineWidth', 0.5);
end
end
view(-16,25) % I favour view over camorbit
Torsten
Torsten 2025년 6월 29일
theta = median(angle(:)); % take the main angle of the domain
throws an error because there is no argument to the angle function.
p = pcolor(X_rot, Y_rot, h); shading interp
h is undefined.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Contour Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by