- Data Size vs. Display Labels: The code above sets display labels at intervals you specify, but it does not change the underlying data or its resolution. It only changes what's shown on the axes.
- Heatmap Function: This approach assumes you're using MATLAB's heatmap function. If you're using a different function or method for creating your heatmap, the approach to setting axis labels might differ.
- Label Overlap: Depending on your figure size and the number of ticks, labels might still overlap. Adjusting the figure size, font size of the labels, or further reducing the number of tick labels can help.
- Categorical Nature of Heatmap Labels: The heatmap function treats axis labels as categories. When you set XDisplayLabels or YDisplayLabels, you're specifying what categories to display, which is why we convert numeric values to strings.
Is it possible to choose the variables displayed for x and y axis in heatmap ?
17 ビュー (過去 30 日間)
古いコメントを表示
Hello there,
I currently have too many axis variables displayed in the heatmap plot, which is becoming unreadable. My map is currently 180x360. For now I have a step of 1, on x and y axis it is shown all the values : 1,2,3, ... , 179,180. I would love to display only some values on the axis such as 0-20-40-60-80 etc. Is here any way to help with that?
Thanks
Maxime H.
0 件のコメント
採用された回答
Shubham
2024 年 3 月 14 日
Hi Maxime,
When dealing with large datasets or plots with numerous data points like your 180x360 heatmap, adjusting the axis ticks and labels can significantly improve readability. In MATLAB, you can customize the appearance of axes in several ways, including setting the tick locations and labels manually.
For a heatmap, assuming you're using the heatmap function, you can adjust the x and y axis tick labels directly through properties of the heatmap object. Here's how you could do it:
% Assuming 'data' is your 180x360 matrix
data = rand(180,360); % Example data for demonstration
% Create the heatmap
h = heatmap(data);
% Total number of ticks you have initially
totalXTicks = size(data, 2); % 360
totalYTicks = size(data, 1); % 180
% Initialize empty labels
xLabels = repmat("", 1, totalXTicks);
yLabels = repmat("", 1, totalYTicks);
% Set labels at desired intervals
xInterval = 20;
yInterval = 20;
xLabels(1:xInterval:end) = string(0:xInterval:(totalXTicks-1));
yLabels(1:yInterval:end) = string(0:yInterval:(totalYTicks-1));
% Apply the labels to the heatmap
h.XDisplayLabels = xLabels;
h.YDisplayLabels = yLabels;
Important Considerations
その他の回答 (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!