setting axis ticks on heatmap

63 次查看(过去 30 天)
Hi,
I am using the heatmap function to plot the values of a matrix with values between 1 and 0
So I am using
A=[1,0.5;0.4,0.2]
heatmap(A)
I would like to add the axis ticks (a time on the x and a height on the y). Any advice?
I tried to use
heatmap(xvalues,yvaluesmì,A)
but that does not work as I have too many values and they are unredable.

采纳的回答

Adam Danz
Adam Danz 2021-1-22
If you want to change the tick labels,
h = heatmap(__);
h.XDisplayLabels = % string array or cell array of character vectors
h.YDisplayLabels = % string array or cell array of character vectors
If you want to change the location of ticks, see this undocumented solution.
Alternatively you can use imagesc() which is more flexible (see 2nd example in this answer).
  2 个评论
giacomo labbri
giacomo labbri 2021-1-22
Thanks for your answer! In the mean time I already changed approach and was using imagesc. The other two solution did not work for me. I think the one you proposed is just to change the labels of the ticks but that was not my poroblem (my problem was I had too may thinks). The undocumented solution produced wierd plot (selecting part of the heat map).
Your link to the imagesc was useful, so thank you, because I had the y axis in revers order and giving
axis xy
solved in for me (I am not sure why).
So my additional question curiosity is why if I do
imagesc([xlow xhigh], [ylow yhigh],A)
I get a plot where on the y axis I have yhigh near the origin and ylow further away?
ylow < yhigh
btw the thing does not change is I switch places to ylow and yhigh
and why giving
imagesc([xlow xhigh], [ylow yhigh],A)
axis xy
solve the problem?
Anyway, thanks again!
Adam Danz
Adam Danz 2021-1-22
编辑:Adam Danz 2021-1-22
In image plotting functions the y Axis is usually reversed. axis xy fixes that. Also see
h = gca;
h.YDir = 'normal';

请先登录,再进行评论。

更多回答(0 个)

标签

Community Treasure Hunt

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

Start Hunting!

Translated by