How to left align YDisplayLabels in a heatmap

7 次查看(过去 30 天)
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?

回答(1 个)

Adam Danz
Adam Danz 2023-5-2
编辑:Adam Danz 2023-5-2
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 个评论
Aseel
Aseel 2023-5-2
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Data Distribution Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by