Having multiple lines in a character array for column labels in a heatmap

8 vues (au cours des 30 derniers jours)
Jenniluyn Nguyen
Jenniluyn Nguyen le 21 Juin 2019
Réponse apportée : CMajhor il y a environ 20 heures
Hi all,
I'm trying to make a heatmap chart and for the x axis I have each column labeled. However, the labels are too big and then they become diagonal (which I am not a fan of). I want to divide some of the labels into multiple lines so that the text does not become diagonal. Is there a way to do that?
I currently have the labels in a character array, i.e:
ColumnLabels = {'Long label 1','Long label 2','Long label 3','Long label 4','Long label 5'}
How should I put a new line in between some of the words so that on the heatmap it looks like:
Long
label 1
and so on? Is there a better way to have these labels stored than a character array? Would much appreciate the help! Thank you!
(Also keep in mind I'm asking something different from the x axis title; I have labels within each column for this heatmap. Thanks!)

Réponse acceptée

dpb
dpb le 22 Juin 2019
Modifié(e) : dpb le 22 Juin 2019
Unless TMW has finally fixed it, the TickLabel interpreter is pretty brain dead...you can do something like
ColumnLabels=strrep(ColumnLabels,'Long ',['Long' char(10)]); % insert linefeed character into strings
xticklabels(ColumnLabels)
and you would think joy would ensue! But, alas...the control character gets interpreted as the end of the strings and you end up with the labels being "Long", "label 1', Long", "label 2", "Long" for the five columns -- not at all what desired.
OTOH, you can see that should work with a TeX interpreter; the same modifed label array used something like
text(0.5,0.5,Columnlabels{1})
will indeed show the full label on the two lines as expected.
One of those mind-numbingly weaknesses that's been around like "since forever" and just never gets fixed. :(

Plus de réponses (1)

CMajhor
CMajhor il y a environ 20 heures
Place \newline where you want the line break. For example:
ColumnLabels = {'Long \newline label 1','Long \newline label 2'}

Catégories

En savoir plus sur Data Distribution Plots dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by