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

66 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Data Distribution Plots 的更多信息

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by