Making a square figure with pcolor

10 ビュー (過去 30 日間)
V.D-C
V.D-C 2020 年 3 月 12 日
コメント済み: darova 2020 年 3 月 18 日
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 !
  4 件のコメント
darova
darova 2020 年 3 月 16 日
Can you attach your code? Data?
V.D-C
V.D-C 2020 年 3 月 17 日
Sorry again, I couldn't answer to your message earlier.
The code looks something like that :
%%% Pcolor
h = figure();
pcolor(x(50:250,50:250),y(50:250,50:250),Tair_mean(50:250,50:250));%% I frame the area of interest
shading flat
colorbar;
ylabel(colorbar,'Air Temprature [°C]');
title(['Mean Daily Air Temperature ' date]);
axis equal
set(gca, 'Color', 'none');
%%% Imagesc
% I transform my coordinates matrices in vectors in order to make them work with imagesc
x_vect = x(:);
y_vect = y(:);
h = figure();
imagesc(x_vect,y_vect,Tair_mean(50:250,50:250)) %% I frame the area of interest
How could I get a square figure like imagesc but with pcolor ?

サインインしてコメントする。

採用された回答

darova
darova 2020 年 3 月 17 日
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
  5 件のコメント
V.D-C
V.D-C 2020 年 3 月 18 日
I will test it as soon as my matlab works !
One question though, how did you do to find the rotation value ?
darova
darova 2020 年 3 月 18 日
  • 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

サインインしてコメントする。

その他の回答 (1 件)

J. Alex Lee
J. Alex Lee 2020 年 3 月 17 日
編集済み: J. Alex Lee 2020 年 3 月 17 日
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));
  1 件のコメント
V.D-C
V.D-C 2020 年 3 月 17 日
Hello, thank you very much for your answer.
I think I will have to forget about the values because to transform my original grid I need a rotation matrix but also to take account of the deformation of the pixels because of the UTM conversion.
I will dig into the image processing toolbox though, as you suggested.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGraphics Performance についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by