x-axis error when adjusting axis label
Show older comments
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 Comments
Callum Heath
on 20 Oct 2020
Edited: Callum Heath
on 20 Oct 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
on 20 Oct 2020
Accepted Answer
More Answers (0)
Categories
Find more on Axis Labels in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
