Reputation: 2633
I have some data that's stored in a 10x11 double. I would like for these labels on the x axis to be multiplied by 30000 and to start at 0 while I want the labels on the y axis to start and 1 and be scaled with 1. So let's say that we have the following:
a=rand(10,11);
heatmap(a)
Which generates the following heatmap
I would like the x axis to be labelled as 0,30000,60000.... and the y axis to remain as is. Anybody know how to do that?
I also want to label both axes with some kind of name (say var1 and var2).
This is in Matlab R2017a.
Upvotes: 1
Views: 785
Reputation: 30155
As of R2017b, you can use the XDisplayLabels
property of the heatmap
object
a=rand(10,11);
hm = heatmap(a);
% Change x axis tick labels to some array
% hm.XDisplayLabels = [0:3e4:(numel(hm.XDisplayLabels)-1)*3e4];
% Change x axis tick labels to the current labels * 3e4 (same result)
hm.XDisplayLabels = str2double(hm.XDisplayData)*3e4 - 3e4;
% To add axes labels to *most* chart types in MATLAB, use `XLabel` and `YLabel` properties
hm.XLabel = 'var2';
hm.YLabel = 'var1';
Output:
The heatmap
object introduced in R2017a has many more options in R2017b, namely XDisplayLabels
doesn't exist in R2017a! You might be better off using the legacy (R2009b - present) HeatMap
object (note the case-sensitivity here). It's less pretty but more customisable...
% Create legacy heatmap
hm = HeatMap(a);
hm.Colormap = bone; % Change colours
% Add y and x tick labels
hm.RowLabels = 10:-1:1;
hm.ColumnLabels = (0:10)*3e4;
% Slant the labels
hm.ColumnLabelsRotate = 50;
% This HeatMap is one of the few plots without XLabel and YLabel!
% use addXLabel and addYLabel instead
hm.addXLabel('var2');
hm.addYLabel('var1');
Output:
Upvotes: 2