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