gui, image plot, ticks, y axis

I am plotting an array "stdmap" of data by using
imagesc(stdmap,[100,500])
As you can see in image below, I want to limit the x & y marks to whole numbers, i.e. 1,2,3 in the y axis.
This number will change, but I just dont want the intermediate values as the y asxis represents line number so i just want integers.
Is it also possible to add the actual values onto the plot too?
Thanks

Respuestas (1)

Geoff Hayes
Geoff Hayes el 16 de Sept. de 2014

1 voto

Jason - you can change the y-ticks on the axes as follows
% create the image
h = imagesc(stdmap,[100,500]);
% get the handle to the parent axes
hAxes = get(h,'Parent');
% create the new y-ticks at the integer positions from 1 to
% the maximum integer
newYTicks = 1:floor(max(get(hAxes,'YTick')));
% set the ticks and the labels for the y-axis
set(hAxes,'YTick',newYTicks,'YTickLabel',num2str(newYTicks))
We use the handle of the image, h, to get the handle to the parent axes, hAxes. Then we obtain the positions of the YTick tick marks (along the y-axis) and convert to newYTicks which will just be the integers from 1 to the (integer once floored) maximum tick position. Then we set the tick positions and labels.
As for adding the actual values on to the plot, do you mean into the figure itself at each "square"? I think you would have to use text objects for that.

4 comentarios

Jason
Jason el 17 de Sept. de 2014
Thankyou for your excellent explanation. i have now tried to extedn this to a graph which has two plots. I already have the handles to the axis by:
[AX,H1,H2] = plotyy(A,B,A,C,'plot');
I then want the first Y axis (i.e. AX(1) to go up in units of 100 (its range is typically 0 to 500), so I used:
newYTicks = 0:100:floor(max(get(AX(1),'YTick')));
% set the ticks and the labels for the y-axis
set(AX(1),'YTick',newYTicks,'YTickLabel',num2str(newYTicks))
But now, every marker has 1, 100, 200 ...500
what have I done wrong?
Geoff Hayes
Geoff Hayes el 17 de Sept. de 2014
Jason - that is bizarre behaviour! I would have done the same as you, so I don't think that you are doing anything wrong. But in this case, you may want to transpose the newYTicks before setting them as the labels
set(AX(1),'YTick',newYTicks,'YTickLabel',num2str(newYTicks'))
The transpose occurs just before the conversion from numbers to strings. I tried it (after reproducing the same behaviour that you observed) and this seemed to work. I didn't have to transpose the YTick input, just that for the YTickLabel.
Jason
Jason el 18 de Sept. de 2014
Thanks Geoff, that's fixed the issue, thanks again for your help. Jason
Volodymyr Zenin
Volodymyr Zenin el 4 de Ag. de 2020
you can also try to let Matlab itself label your ticks, i.e.,
set(AX(1),'YTick',newYTicks)

Iniciar sesión para comentar.

Categorías

Preguntada:

el 16 de Sept. de 2014

Comentada:

el 4 de Ag. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by