Is it possible to choose the variables displayed for x and y axis in heatmap ?

19 vues (au cours des 30 derniers jours)
Maxime
Maxime le 14 Mar 2024
Commenté : Maxime le 18 Mar 2024
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.

Réponse acceptée

Shubham
Shubham le 14 Mar 2024
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
  • 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.

Plus de réponses (0)

Catégories

En savoir plus sur Data Distribution Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by