How to left align YDisplayLabels in a heatmap

8 views (last 30 days)
Aseel
Aseel on 2 May 2023
Commented: Aseel on 2 May 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?

Answers (1)

Adam Danz
Adam Danz on 2 May 2023
Edited: Adam Danz on 2 May 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 Comment
Aseel
Aseel on 2 May 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.

Sign in to comment.

Categories

Find more on Data Distribution Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!