Right Y-Label for Heatmap
13 views (last 30 days)
Show older comments
I want to add a right y-label with different values for my heatmap. The label I want to add will not be connected with the data in this case. It's just for representation purposes. Here is my code:
cdata = [0.516 0.246 0.230 0.856 0.996 0.324;0.079 1.000 0.021 0.198 0.045 0.046; 0.017 0.115 0.010 0.036 0.006 0.046;0.004 0.008 0.001 0.003 0.000 0.004;0.345 1.000 0.555 0.824 0.527 0.327];
xvalues = {'1200','1600','2000','2400','2800','3200'};
yvalues = {'0.2','0.4','0.6','0.8','1.0'};
h = heatmap(xvalues,yvalues,cdata);
h.Title = 'P-Values from T-Test';
h.XLabel = 'Traffic Demand (veh/hr)';
h.YLabel = 'Compliance Rate %';
The right-side label will contain, for example, the following values: {'0.1','0.3','0.5','0.7','0.9'};
Any help will be appreciated.
0 Comments
Answers (1)
Benjamin Kraus
on 24 Feb 2018
There is no way to do this built-in to heatmap. The only way I can think to do this is to add a second axes with the desired tick labels. However, this will create tick labels that overlap with the colorbar.
If you are willing to turn the colorbar off, this may work:
ax = axes('YAxisLocation','right','XTick',[],'YDir','reverse',...
'YLim',[0.5 5.5],'YTick',1:5,'YTickLabel',{'0.1','0.3','0.5','0.7','0.9'});
cdata = [0.516 0.246 0.230 0.856 0.996 0.324;0.079 1.000 0.021 0.198 0.045 0.046; 0.017 0.115 0.010 0.036 0.006 0.046;0.004 0.008 0.001 0.003 0.000 0.004;0.345 1.000 0.555 0.824 0.527 0.327];
xvalues = {'1200','1600','2000','2400','2800','3200'};
yvalues = {'0.2','0.4','0.6','0.8','1.0'};
h = heatmap(xvalues,yvalues,cdata,'OuterPosition',[0 0 1 1],'ColorbarVisible','off');
h.Title = 'P-Values from T-Test';
h.XLabel = 'Traffic Demand (veh/hr)';
h.YLabel = 'Compliance Rate %';
ax.Position = h.InnerPosition;
0 Comments
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!