Changing the number of xticks on heatmat (without changing the data)

I am creating a heat map where the x-axis is a datetime when a measurement was taken. I have about 100 times when data was recorded. When all 100 ticks show up on the x-axis, its not legible so I want to only display time labels for every 10th measurement. I have tried using
ax = gca;
ax.XDisplayLabels = [date(1:10:end)];
But I get the error message "'XDisplayLabels' vector must contain the same number of elements as the 'XDisplayData vector'".
How do I map all 100 columns of data but only display every 10th xtick label?

Réponses (1)

Try:
xt=xticks;
xticks(xt(1:10:end))
If that doesn't work, it sounds like
ax = gca;
ax.XDisplayData = [date(1:10:end)];
% probably not necessary
ax.XDisplayLabels = [date(1:10:end)];
is the version of your solution that will work.
p.s. be warned that "date" is an existing function

5 commentaires

Using the first one, I get the erro message "using xticks with heatmap is not supported"
For the second, it only maps every tenth column of data, and I need all columns data displayed.
ah, haven't worked with heatmaps specifically. Try this:
% copy over the xticklabels
tmp=ax.XDisplayLabels;
% set all but 1,11,21,... to an empty string
tmp(setdiff(1:end,1:10:end)) = {''};
% update the ticklabels
ax.XDisplayLabels = tmp;
Yeah, heatmap is weird because it doesn't let you treat the labels as xticks and you can't select to only display certain labels. This worked though! Thank you!
Do you have any idea how I could set the tick angle to 45 degreees?
It's not looking good. The properties I'd change just don't seem to exist for heatmap objects
Yeah, same. These properties don't seem to exist for heatmap, which is frustrating. Thanks for your help though

Connectez-vous pour commenter.

Catégories

En savoir plus sur Data Distribution Plots dans Centre d'aide et File Exchange

Produits

Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by