How to rotate pcolor plot with an angle?

조회 수: 40 (최근 30일)
Riyadh
Riyadh 2024년 11월 4일 7:08
댓글: Riyadh 2024년 11월 4일 9:48
Hello All,
I want to rotate pcolor plot with an angle.
How can I do it?
Thanks in advance.

답변 (1개)

Shashi Kiran
Shashi Kiran 2024년 11월 4일 9:19
To rotate a "pcolor" plot by a specified angle, you can use a rotation matrix.
Assuming you want to rotate the plot by an angle "theta" in an anticlockwise direction around the origin, here is how you can achieve this using an example from https://www.mathworks.com/help/matlab/ref/pcolor.html:
% Original data
X = [1 2 3; 1 2 3; 1 2 3];
Y = X';
mymap = [1 0 0; 0 1 0; 0 0 1; 1 1 0; 0 0 0];
C = [3 4 5; 1 2 5; 5 5 5];
% Plot the original data
pcolor(X, Y, C);
colormap(mymap);
theta = 45;
theta_rad = deg2rad(theta);
% 2D rotation matrix
R = [cos(theta_rad) -sin(theta_rad); sin(theta_rad) cos(theta_rad)];
% Rotate coordinates
XY_rotated = R * [X(:)'; Y(:)'];
X_rotated = reshape(XY_rotated(1, :), size(X));
Y_rotated = reshape(XY_rotated(2, :), size(Y));
% Plot rotated data
pcolor(X_rotated, Y_rotated, C)
colormap(mymap)
Refer to the following documentations for more details:
  1. pcolor: https://in.mathworks.com/help/matlab/ref/pcolor.html
Hope this helps.

카테고리

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