Boxplot with multiline x axis labels
Mostrar comentarios más antiguos
Hello,
I'm trying to create a boxplot for two groups. Each group's label is multi line. I have tried the approach below, but the first line of each label is drawn on top of the x axis, while the second is drawn below the x axis (please try the code below)
Does anyone know how to make the two lines be drawn below the x axis in a boxplot?
Thanks
%%%%%%%%%%%
Dist1 = rand(10, 1);
Dist2 = rand(10, 1);
group = [repmat(cellstr(sprintf('First Line G1\nSecond Line G1')), length(Dist1), 1); ...
repmat(cellstr(sprintf('First Line G2\nSecond Line G2')), length(Dist2), 1)];
figurePlot = figure('visible', 'on');
boxplot([Dist1;Dist2], group)
ylabel('Y Label');
Respuesta aceptada
Más respuestas (1)
Walter Roberson
el 4 de Oct. de 2011
0 votos
Using string with newlines in them is not promised to work for any of the MATLAB graphical text operations that I can think of at the moment.
Some graphical operations permit character arrays with multiple rows; some graphical operations permit strings with the lines separated by '|'; some graphical operations permit cell arrays of strings; some permit TeX or LaTeX that include coded indications of line breaks. And some graphical text operations just plain only permit single lines. Sometimes the easiest way to work around the matter is to go in to the object (e.g., axes) properties and bash the usual text object handle to be an annotation object handle.
4 comentarios
Fangjun Jiang
el 4 de Oct. de 2011
In this case, the OP is not using newline. cellstr() is used. However, I found that in R2007b, it is displayed in one line. In R2010b, it is displayed in two lines.
Walter Roberson
el 4 de Oct. de 2011
cellstr() does not break the strings at newline characters. A "row" for cellstr purposes is the same thing as a MATLAB array row.
Walter Roberson
el 4 de Oct. de 2011
Did you perhaps miss the sprintf('....\n...') ? That creates a character vector with the \n replaced by char(10) and does *not* create two rows of characters.
Fangjun Jiang
el 4 de Oct. de 2011
Yep. I see you point.
>> a=['abc';'efg'];
A=cellstr(a)
b=sprintf('abc\nefg');
B=cellstr(b)
A =
'abc'
'efg'
B =
[1x7 char]
Categorías
Más información sobre Labels and Annotations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!