How to add newline to barplot x label?
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
regulo rosado
el 14 de Sept. de 2020
Comentada: regulo rosado
el 15 de Sept. de 2020
I've been searching for some time now, and there seems to be no posible way to add labels to the columns of a barplot which may include more than one line. Or at least, set the labels to wrap text to avoid overlaping. My code:
y = [100 200 300];
b = bar(y);
grid on
hold on
name = {'label1','label1'; ...
'label2','label2'; ...
'label3','label3'};
set(gca,'xticklabel',name)
bar(1,y(1),'r');
bar(2,y(2),'g');
bar(3,y(3),'b');
ylim([0,400]);
ylabel('Units [u]');
text(1:length(y),y,num2str(y',4),'vert','bottom','horiz','center');
hold off
What I need is to be able to have a bar plot labeled like this one:

( I edited the bar labels on paint)
I want to label the bars this way because my bar labels are long.
I thank you in advance for your time.
0 comentarios
Respuesta aceptada
Walter Roberson
el 14 de Sept. de 2020
'$\begin{array}{c}upper\\lower\end{array}$'
You will need to set the axes TickLabelInterpreter property to 'latex'
For each column you want, you will need to add another character to the {c} portion. The 'c' stands for "centered"; you can also use "l" (left) and "r" (right). \\ marks the break. Put && between column entries.
Más respuestas (0)
Ver también
Categorías
Más información sobre Color and Styling en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!