フィルターのクリア

how to add grid to imagesc?

128 ビュー (過去 30 日間)
Rabih Sokhen
Rabih Sokhen 2022 年 1 月 10 日
コメント済み: DGM 2024 年 5 月 13 日
clear all
clc
a=rand(20,50)
x=linspace(-1,1,20)
y=linspace(-1,1,50)
imagesc(x,x,a)
I would like to add grid only at the border of every pixel in a way wen I zoom in only the initial grid appear
can someone help me with this.
thank you in advance
  3 件のコメント
Chandan
Chandan 2024 年 5 月 12 日
how to make the grid in crop field image
DGM
DGM 2024 年 5 月 13 日
What grid in what image?
If you have a question to ask, use the Ask link at the top of the page to ask a question instead of hiding vague comments in old threads.

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

採用された回答

DGM
DGM 2022 年 1 月 11 日
It depends how you want to visualize the data. Tools like imshow() or imagesc() represent the data points at the center of each facet in the displayed image. Tools like pcolor() represent the data at the vertices. If the latter is what you intend, then just use pcolor() instead of imagesc().
If you actually want the matrix represented as an image, then you'll have to create the grid. One way would be to just overlay a mesh plot.
s = [4 5]; % [y x]
xrange = [-1 1]; % imagesc only needs the endpoints
yrange = [-1 1];
a = rand(s);
dx = diff(xrange)/(s(2)-1);
dy = diff(yrange)/(s(1)-1);
xg = linspace(xrange(1)-dx/2,xrange(2)+dx/2,s(2)+1);
yg = linspace(yrange(1)-dy/2,yrange(2)+dy/2,s(1)+1);
hi = imagesc(xrange,yrange,a); hold on
hm = mesh(xg,yg,zeros(s+1));
hm.FaceColor = 'none';
hm.EdgeColor = 'k';
You might try to do it by setting the grid properties of the axes, but you'll have to contend with the ticklabels if you do that.
As to how you make the added grid appear only at certain zoom levels, you'd have to create some sort of custom callback to do that. I'll leave that to someone else.
  9 件のコメント
Rabih Sokhen
Rabih Sokhen 2022 年 1 月 14 日
thank you DGM, it works
Kristoffer Walker
Kristoffer Walker 2024 年 1 月 23 日
This is a long-standing RSI issue. This seems like a low-hanging fruit that someone could easily create an API for to make it so much easier for those of us who use and love imagesc. Just add the property "grid", "on". How hard can it be?

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

その他の回答 (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