Grid in imagesc() not lining up to grid limits?
10 ビュー (過去 30 日間)
古いコメントを表示
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
0 件のコメント
回答 (1 件)
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 件のコメント
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 Exchange で Axis Labels についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!