How to left align YDisplayLabels in a heatmap
8 views (last 30 days)
Show older comments
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?
0 Comments
Answers (1)
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';
See Also
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!