How to rotate pcolor plot with an angle?
40 views (last 30 days)
Show older comments
Hello All,
I want to rotate pcolor plot with an angle.
How can I do it?
Thanks in advance.
0 Comments
Answers (1)
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:
Hope this helps.
See Also
Categories
Find more on Contour Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!