MATLAB Answers

setting axis ticks on heatmap

37 views (last 30 days)
giacomo labbri
giacomo labbri on 22 Jan 2021
Edited: Adam Danz on 22 Jan 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.

Accepted Answer

Adam Danz
Adam Danz on 22 Jan 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 Comments
Adam Danz
Adam Danz on 22 Jan 2021
In image plotting functions the y Axis is usually reversed. axis xy fixes that. Also see
h = gca;
h.YDir = 'normal';

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by