How to add a colorbar in a heatmap?

6 ビュー (過去 30 日間)
Julia Moore
Julia Moore 2020 年 6 月 2 日
編集済み: Ayden Clay 2020 年 6 月 2 日
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 Center および File ExchangeColormaps についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by