How to change X and Y axis values on a heatmap.

147 ビュー (過去 30 日間)
Myles Stapelberg
Myles Stapelberg 2018 年 5 月 14 日
編集済み: Benjamin Kraus 2018 年 7 月 26 日
Hi.
So I have a heatmap, that displays a 50 x 50 array of values. I want the X and Y Axis to go from 1 to 10 (with each value representing 5 of the previous), but right now, since I have a 50 x 50 array, each axis goes from 1-50. This is unsightly and I wan't to change this.
I have tried changing the XDispayLabel and YDisplayLabel in code, and in the editor after creating the heatmap, but to no avail.I kept on getting an error message saying that the cell was out of the dimensions of XDisplay or YDisplay.
Another question (Albeit, less important) is how to choose colors that are a bit easier to differentiate from, and how to set the limit of the colors to custom limits, since my values are very close together and are getting grouped up accordingly. I am running R2018a. Here is my code for the Heat map:
if true
% code
%heatmap
h = heatmap(total_cost, 'Colormap', parula(20), 'ColorbarVisible', 'on', 'XLabel', 'Installed MW of Solar (1000MW per Tick)', 'YLabel', 'Installed MW of Wind(1000MW per Tick)');
h.title(['Optimal Mix of Wind and Solar', 'FontSize', 30]);
h.xlabel(['Installed MW of Solar (1000MW per Tick)', 'FontSize', 24]);
h.ylabel(['Installed MW of Wind (1000MW per Tick)', 'FontSize', 24]);
h.XDisplayLabel[1:10:100];
h.YDisplayLabel[1:10:100];
end
Thank you in advance.

採用された回答

Aditya Salveru
Aditya Salveru 2018 年 5 月 14 日
編集済み: Aditya Salveru 2018 年 5 月 15 日
Hi Myles,
You can change the x axis and y axis values by providing them as input to heatmap.
Create numemric arrays x,y within the range required and provide them as arguments.
x=linspace(1,10,50);
y=linspace(1,10,50);
h = heatmap(x,y,total_cost, 'Colormap', parula(20), 'ColorbarVisible', 'on', 'XLabel', 'Installed MW of Solar (1000MW per Tick)', 'YLabel', 'Installed MW of Wind(1000MW per Tick)');
I am attaching the snapshot of a heatmap with 50x50 random values with x and y axis normalized to 1-10.
Thanks,
Aditya
  2 件のコメント
Myles Stapelberg
Myles Stapelberg 2018 年 5 月 14 日
Hello Aditya,
Thank you for your response. I just tried your method, and while I was able to scale down the axis, I still have decimal numbers in between the whole numbers on the axis.
Is there a way to only display the whole numbers? The less clutter on this heatmap the better!
Thank you in advance.
Myles
Aditya Salveru
Aditya Salveru 2018 年 5 月 15 日
Hi,
I think you can use 'round' function to round off the decimal digits of x and y to 1 or 2 digits and it may look better.
Thanks.

サインインしてコメントする。

その他の回答 (1 件)

Benjamin Kraus
Benjamin Kraus 2018 年 7 月 26 日
編集済み: Benjamin Kraus 2018 年 7 月 26 日
Sorry I'm late to this question, but in case you are still looking for an answer to your second question ("Another question is how to choose colors that are a bit easier to differentiate from, and how to set the limit of the colors to custom limits, since my values are very close together and are getting grouped up accordingly."):
You can try the ColorScaling property. Setting the value to log may help you better differentiate your data.

カテゴリ

Help Center および File ExchangeData Distribution Plots についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by