10 views (last 30 days)

Hello,

I have 2 matrices for x and y coordinates, and a matrix of temperatures. From the matrices, I make 2 coordinate vectors of size 99000 x 1 from the 300 x 300 matrices.

When I plot with imagesc and the vectors, I have the linked result. When I plot with pcolor and the coordinates matrices, I have the other figure.

I would like to make the second figure (plotted with pcolor) square like the one plotted with imagesc. How could I achieve that ?

Thanks in advance !

darova
on 17 Mar 2020

You can either use pcolor without X and Y vectors

newTair = flipud(Tair_mean(50:250,50:250)); % flip matrix upside-down

pcolor(newTair)

Or you can create rotate X and Y

a = 51;

R = [cosd(a) sind(a);-sind(a) cosd(a)];

V = R*[x(:) y(:)]';

x1 = reshape(V(1,:),size(x));

y1 = reshape(V(2,:),size(x));

pcolor(x1(50:250,50:250),y1(50:250,50:250),Tair_mean(50:250,50:250));%% I frame the area of interest

J. Alex Lee
on 17 Mar 2020

darova's code seems to work for me...

rather than axis tight, I think you want

set(gca,'DataAspectRatio',[1 1 1])

darova has already identified that you only need a rotation through 51deg to "rectify" your coordinates, so you woulnd't need to fiddle around with fitgeotrans().

darova
on 18 Mar 2020

- One question though, how did you do to find the rotation value ?

Good question. I used my eyes to calculate it. But maybe it's not the best way

dx = x(2) - x(1);

dy = y(2) - y(1);

a = 90 + atan2d(dy,dx)

a =

50.9309

Sign in to comment.

J. Alex Lee
on 17 Mar 2020

Edited: J. Alex Lee
on 17 Mar 2020

Your coordinate grid matrices x and y are not "aligned" with the axes. You can see this if you just do

plot3(x,y,zeros(size(x)),'.k')

view(2)

So I would say your pcolor code is giving you the correct rendering, and imagesc behavior seems anomalous, since your values of x and y (called x_vect and y_vect in your code), do not follow the requirements of imagesc:

per the documentation, x and y should either be vectors of respective lengths size(Tair_mean), or 2-element vectors specifying only the corner coordinates (implicitly assume on a rectangular canvas aligned with axes), or scalars specifying only 1 corner. As you supply the entire grid in a long vector, it must be assuming you only care about the first and last points, or something like that.

If you want to align with axes, I guess you have 2 options:

- Forget about the actual coordinate values and simply issue

pcolor(Tair_mean(50:250,50:250));

- Transform your original grid (x,y) to a new grid aligned with the axes, using some rotation (and maybe a skew). If you have the image processing toolbox, you can play with https://www.mathworks.com/help/images/ref/fitgeotrans.html

Sign in to answer this question.

Opportunities for recent engineering grads.

Apply Today
## 4 Comments

## Direct link to this comment

https://fr.mathworks.com/matlabcentral/answers/510500-making-a-square-figure-with-pcolor#comment_809002

⋮## Direct link to this comment

https://fr.mathworks.com/matlabcentral/answers/510500-making-a-square-figure-with-pcolor#comment_809002

## Direct link to this comment

https://fr.mathworks.com/matlabcentral/answers/510500-making-a-square-figure-with-pcolor#comment_810545

⋮## Direct link to this comment

https://fr.mathworks.com/matlabcentral/answers/510500-making-a-square-figure-with-pcolor#comment_810545

## Direct link to this comment

https://fr.mathworks.com/matlabcentral/answers/510500-making-a-square-figure-with-pcolor#comment_810582

⋮## Direct link to this comment

https://fr.mathworks.com/matlabcentral/answers/510500-making-a-square-figure-with-pcolor#comment_810582

## Direct link to this comment

https://fr.mathworks.com/matlabcentral/answers/510500-making-a-square-figure-with-pcolor#comment_811019

⋮## Direct link to this comment

https://fr.mathworks.com/matlabcentral/answers/510500-making-a-square-figure-with-pcolor#comment_811019

Sign in to comment.