How to rotate pcolor plot with an angle?
40 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello All,
I want to rotate pcolor plot with an angle.
How can I do it?
Thanks in advance.
0 commentaires
Réponses (1)
Shashi Kiran
le 4 Nov 2024 à 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.
Voir également
Catégories
En savoir plus sur Contour Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!