x-axis error when adjusting axis label
Mostrar comentarios más antiguos
Hello all,
i am having trouble with x-axis adjustment.
Below is the original code before implementing any change to the x-axis.
As it is to be seen on the first picture, the x-axis labeling is clustered and the numbers are not horizontally placed.
figure
boxplot(TT3.P,round(TT3.OT),'PlotStyle','compact')
title('Power consumption depending on the outside temperature')
xlabel('Outside temperature [°C]')
ylabel('Heating power [kW]')
grid on

In order to correct the issues mentioned above i have added 'set' to adjust the x-axis.
figure
boxplot(TT3.P,round(TT3.OT),'PlotStyle','compact')
title('Power consumption depending on the outside temperature')
xlabel('Outside temperature [°C]')
xlim([-15 35])
ylabel('Heating power [kW]')
set(gca, 'XLim',[-15 35], 'XTick', -15:5:35 , 'XTickLabel', -15:5:35);
grid on
However the plotted figure does not represent what i intended to show.
It simply shifted to the right and is not showing the negative side of values on the x-axis (as it is to be seen in the picture below).

What may be the problem and how may i proceed?
Thank you.
2 comentarios
Callum Heath
el 20 de Oct. de 2020
Editada: Callum Heath
el 20 de Oct. de 2020
Try either:
set(gca, 'XLim',[-15 35], 'XTick', -15:5:35 , 'XTickLabel', 'auto');
Or, XTickLabel requires a 1xn cell array with string inputs! So something like this:
xticklabels=cell(1,length(-15:5:35));
indx = 1;
for i =-15:5:35
xticklabels{indx} = num2str(i);
indx=indx+1;
end
figure
boxplot(TT3.P,round(TT3.OT),'PlotStyle','compact')
title('Power consumption depending on the outside temperature')
xlabel('Outside temperature [°C]')
xlim([-15 35])
ylabel('Heating power [kW]')
set(gca, 'XLim',[-15 35], 'XTick', -15:5:35 , 'XTickLabel', xticklabels);
grid on
Sehoon Chang
el 20 de Oct. de 2020
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Axis Labels 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!

