MATLAB: Plot does not match with x tick label

plotx-label

This is my code,
figure(5)
plot(t1,tanggal_psminggu_kebayoran)
hold on
plot(t1,tanggal_psminggu_ui)
plot(t1,tanggal_psminggu_manggarai)
plot(t1,tanggal_cawang_pgc)
plot(t1,tanggal_cilincing_perintis)
hold off
grid on
set(gca,'Xticklabel',t1),set(gca,'XTick',1:numel(t1))
xlabel('Tanggal'); ylabel('Jumlah Bus');
legend({'TERM PS.MINGGU - KEBAYORAN','TERM PS.MINGGU - UNIVERSITAS INDONESIA','TERM PS. MINGGU - MANGGARAI','CAWANG - PGC - PLUMPANG','CILINCING - PERINTIS '},'Location','bestoutside')
title('Jumlah Bus Tiap Rute Pada Januari 2014')

Best Answer

XTickLabel can have a value that does not correspond to the actual XTick value. That is likely what has happened here.
You first plot the data, so the original X values are set by the values in T1.
You then change the tick labels to be the values of T1. This breaks the connection of the label to the tick location. It is also unnecessary, since the tick labels are already the values of T1.
Then you set the XTick locations, which moves the labels to the locations X=[1, 2, ..., 17] rather than the values of T1.
Remove the following line of code and see if that creates the plot you want.
set(gca,'Xticklabel',t1),set(gca,'XTick',1:numel(t1))