How can I modify the X and Y axis tick labels for a Heatmap chart?
299 ビュー (過去 30 日間)
古いコメントを表示
MathWorks Support Team
2020 年 1 月 2 日
回答済み: MathWorks Support Team
2020 年 3 月 30 日
How can I modify the X and Y axis tick labels for a 'Heatmap' chart?
My data is too dense (100 ticks on each axis) and tick labels overlap each other if all of them are plotted.
For example, how can I only display every '5th' tick label, instead of all of them?
採用された回答
MathWorks Support Team
2020 年 1 月 2 日
I understand that you are trying to change the displayed tick labels on the X and Y axis of a 'Heatmap'.
For this you need to set the 'XDisplayLabels' property of the heatmap object.
The following link provides more information on this:
<https://www.mathworks.com/help/matlab/ref/matlab.graphics.chart.heatmapchart-properties.html#d117e582387>
I created an example MATLAB script to demonstrate how this may be done, as follows:
% Create a random 2-D matrix and make a heatmap
A = randi(100,100);
h = heatmap(A);
Create custom X tick labels such that every tick label is blank (i.e., " ") except ticks which are divisible by 5 (i.e., 5, 10, 15, ...)
XLabels = 1:100;
% Convert each number in the array into a string
CustomXLabels = string(XLabels);
% Replace all but the fifth elements by spaces
CustomXLabels(mod(XLabels,5) ~= 0) = " ";
% Set the 'XDisplayLabels' property of the heatmap
% object 'h' to the custom x-axis tick labels
h.XDisplayLabels = CustomXLabels;
In the above example we create a random (100 X 100) matrix of numbers 'A' and use it to create a Heatmap 'h':
Assuming that we only want to display every 5th tick label on the X-axis of the Heatmap, I create a (1 X 100) array of strings 'CustomXLabels'.
Every element of 'CustomXLabels' is an white space (i.e., ' ' ) except for the ones that are divisible by 5 (these elements will be strings like: '5', '10', '15', ...., '100').
Next, we set the 'XDisplayLabels' property of the Heatmap object 'h' with the custom labels array 'CustomXLabels', which sets the X-Axis tick labels as per our requirements:
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Data Distribution Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!