setting axis ticks on heatmap

49 visualizaciones (últimos 30 días)
giacomo labbri
giacomo labbri el 22 de En. de 2021
Editada: Adam Danz el 22 de En. de 2021
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.

Respuesta aceptada

Adam Danz
Adam Danz el 22 de En. de 2021
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 comentarios
giacomo labbri
giacomo labbri el 22 de En. de 2021
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 el 22 de En. de 2021
Editada: Adam Danz el 22 de En. de 2021
In image plotting functions the y Axis is usually reversed. axis xy fixes that. Also see
h = gca;
h.YDir = 'normal';

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by