How to rotate pcolor plot with an angle?

40 views (last 30 days)
Riyadh
Riyadh on 4 Nov 2024 at 7:08
Commented: Riyadh on 4 Nov 2024 at 9:48
Hello All,
I want to rotate pcolor plot with an angle.
How can I do it?
Thanks in advance.

Answers (1)

Shashi Kiran
Shashi Kiran on 4 Nov 2024 at 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.

Categories

Find more on Contour Plots in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!