How to left align YDisplayLabels in a heatmap

10 vues (au cours des 30 derniers jours)
Aseel
Aseel le 2 Mai 2023
Commenté : Aseel le 2 Mai 2023
Hello,
I have generated a heatmap on MATLAB. The display labels for the y-axis are included in a line that looks like the following:
labels={'aaaa','bbb','c'};
h1=heatmap(rand(3,3));
h1.YDisplayLabels=labels;
I would like the YDisplayLabels to be left aligned in the window and not right-aligned, which is the default. Can you please help me figure out the syntax to do that?

Réponses (1)

Adam Danz
Adam Danz le 2 Mai 2023
Modifié(e) : Adam Danz le 2 Mai 2023
You can pad the labels with empty spaces so that all labels are the same length using
labels={'aaaa','bbb','c'};
h1=heatmap(rand(3,3));
drawnow
labelsPadded = pad(labels,max(strlength(labels)));
h1.YDisplayLabels = labelsPadded;
but unless you're using a fixed width font, it may not produce exact right alignment.
h1.FontName = 'consolas';
  1 commentaire
Aseel
Aseel le 2 Mai 2023
Thanks! Yes, this would be great but I need the font to be Arial or Helvetica so unfortunately it doesn't end up looking right.

Connectez-vous pour commenter.

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