How to add a colorbar in a heatmap?

5 次查看(过去 30 天)
Hey guys!
I am trying to do a heatmap, using a the heatmap function. But I am not being capable of adding a colorbar. Does anyone know if it is possible using the MATLAB version 2016a?
Also my current heatmap is like this, I would like to invert the beggining of the rows position. Is it possible that the row number 1 start on the first line not in the last one? And how could I eliminate the elements above the main diagonal?
Thnkss

采纳的回答

Ayden Clay
Ayden Clay 2020-6-2
编辑:Ayden Clay 2020-6-2
Hi Julia!
In 2006a MATLAB introduced the colorbar command that automatically adds a colorbar and it can be included underneath any plot function and it will automatically generate a colorbar. For more options type
doc colorbar
into the matlab command window.
As for the second half of your question, you can control the axis direction using
set(gca,'YDir','reverse');
which ought to solve your issue. As for eliminating the values above the diagonal you would have to mess with the data that you are using to generate the heatmap. Since this is in a table (for use with the heatmap command).
Suppose your table is called T, then you may be able to use the following:
for i = 1:size(T,1)-1
T{i,i+1:end} = [];
end
Though I admit my knowledge of tables is severely limited.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Colormaps 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by