Grid in imagesc() not lining up to grid limits?

10 ビュー (過去 30 日間)
Jonathan Schroder
Jonathan Schroder 2019 年 6 月 13 日
コメント済み: Shunichi Kusano 2019 年 6 月 13 日
Hey everyone,
I'm trying to figure out why my plotted matrix here, a 10 x 10 matrix with mostly 0s, represented in deep blue, is not lining up with my axes of this graph! I have tried playing with the Xlim/YLim as well as XTick/YTick to no avail. It's driving me nuts - I want to be able to represent this data in a clear and concise way.
That yellow block you see is supposed to be 5 units long, and the orange block is supposed to be 4 units long. Something is amiss here, but I am not equipped to solve it with my developing knowledge of plotting figures.
Is my plotting tool the wrong one to use? Am I missing a crucial setting for this? I will be happy to provide more information.
Thank you for your help!
hey l6SscBU.png

回答 (1 件)

Shunichi Kusano
Shunichi Kusano 2019 年 6 月 13 日
Hi Jonathan. The pixel coordinate is normal in your image. The center of each pixel is located at the cross of the grid lines. Now, you need to specify the coordinate of your image like:
imagesc([1:size(img,2)]-0.5, [1:size(img,1)]-0.5, img); % img is your image
This makes your image lined up with your grid. hope this helps.
  2 件のコメント
Jonathan Schroder
Jonathan Schroder 2019 年 6 月 13 日
編集済み: Jonathan Schroder 2019 年 6 月 13 日
Shunichi,
Thank you for this response! I see that this essentially boils down to
imagesc([0.5:9.5], [0.5,9.5],img)
If I type in what you gave me, it works perfectly! However, I want to be able to save this in the property inspector?
What exactly do these need to correlate to in the properties manager? If I set both my Xlim and Ylim to [0.5,9.5], I get the shapes in the proper places, but now the grid placements are all off!
Shunichi Kusano
Shunichi Kusano 2019 年 6 月 13 日
I may misunderstand what you want, though, how about this? I just added lines manually.
img = rand(10,10); % dummy data
imagesc(img);
line(repmat([1.5:1:9.5],2,1),repmat([0;11], 1, 9), 'Color', 'red'); % vertical
line(repmat([0;11], 1, 9), repmat([1.5:1:9.5],2,1), 'Color', 'red'); % horizontal
ax = gca;
ax.TickLength = [0 0];

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

カテゴリ

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

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by