the problem of shifting and pcolor

3 ビュー (過去 30 日間)
jenka
jenka 2012 年 7 月 4 日
コメント済み: Chad Greene 2015 年 5 月 1 日
Hi all, I am doing this code, and it appears that my text pixels are shifted compared to my pcolor output. Any suggestions. Note, my data contains NaN so image() does not work. Also, x and y are both of matrix types, not vectors. Any suggestions would be really appreciated. THANKS!
m_proj('stereographic','lat',90,'radius',60, 'rotateangle',270)
[lat_new,lon_new] = ndgrid(lat,lon);
[x,y] = m_ll2xy(lon_new,lat_new);
h = pcolor(x,y, cor); hold on;axis xy;
shading flat
sz = size(lat_new);
for i=1:sz(1)
for j=1:sz(2)
if prob(i,j)==1
%THESE APPEAR TO BE SHIFTED:(((
g = text(x(i,j),y(i,j),'*');
set(g,'fontsize',[10]);
set(g,'fontweight','bold');
hold on;
%z = text(x(i,j),y(i,j),num2str(cor(i,j)));
end
end
end

回答 (2 件)

Image Analyst
Image Analyst 2012 年 7 月 4 日
Right. We talked about this before. Don't use pcolor. image() and imshow() have no problem handling images with nans in them - I actually tried and verified that. You just have to make sure x and y are in the range of 1 to sz(1) or sz(2)
  4 件のコメント
jenka
jenka 2012 年 7 月 4 日
sorry here is the code use:
m_proj('stereographic','lat',90,'radius',60, 'rotateangle',270)
[lat_new,lon_new] = ndgrid(lat,lon);
[x,y] = m_ll2xy(lon_new,lat_new);
%lon and lat are vectors
h = image(lon,lat, cor);
sz = size(lat_new);
for i=1:sz(1)
for j=1:sz(2)
if prob(i,j)==1
%THESE APPEAR TO BE SHIFTED:(((
g = text(x(i,j),y(i,j),'*');
set(g,'fontsize',[10]);
set(g,'fontweight','bold');
hold on;
end
end
end
Image Analyst
Image Analyst 2012 年 7 月 4 日
I don't have those functions. If they're in the mapping toolbox, I don't have that. You can use a colormap to get rid of the blue, like
imshow(yourArray, []);
colormap(gray(256));

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


jenka
jenka 2012 年 7 月 4 日
This is exactly the issue with pcolor I am facing. I am just not sure how to solve this small problem: p_color with shading flat will draw a panel between the (i,j),(i+1,j),(i+1,j+1),(i,j+1) coordinates of the X/Y matrices with a color corresponding to the data value at (i,j). Thus everything will appear shifted by one half a pixel spacing.
  2 件のコメント
Walter Roberson
Walter Roberson 2012 年 7 月 4 日
Yes, that is how it is designed, and is the reason not to use pcolor()
Chad Greene
Chad Greene 2015 年 5 月 1 日
Here's a depiction of some funny effects using pcolor.

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

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by