How can I edit x label so it doesn't overlap each other?
6 views (last 30 days)
Show older comments
This is my code at the moment,
figure(1)
bar(tabel_bus.jumlah_bus);
set(gca,'Xticklabel',tabel_bus.rute_tujuan)
grid on
xlabel('Rute Tujuan'); ylabel('Jumlah Bus');
title('Jumlah Bus Tiap Rute')
This is how my bar chart look,

0 Comments
Answers (1)
Aashray
on 29 Aug 2025 at 9:14
I understand that you are plotting a bar chart where the x-axis labels (route names) are quite long, and they currently overlap each other. This happens because by default MATLAB places labels horizontally, so when they are long and there are many of them, they cannot fit nicely.
A simple way to fix this is to rotate the labels using “xtickangle”.
Here is a small example with dummy data that shows the approach:
% Sample data
jumlah_bus = [3 7 12 5 9 11];
rute_tujuan = { ...
'BLOK M - CILEDUG', ...
'CAWANG - PGC', ...
'PLUMPANG - LINCING', ...
'PERINTIS - PANTENG', ...
'SUNTER - PRUMO', ...
'DUREN KOSAMBI - KAMAL'};
% Create figure
figure
bar(jumlah_bus);
% Apply labels
set(gca,'XTickLabel',rute_tujuan)
% Rotate to avoid overlap
xtickangle(45);
xlabel('Rute Tujuan');
ylabel('Jumlah Bus');
title('Jumlah Bus Tiap Rute');
grid on
This will show each route on two stacked lines, making the axis less cluttered.
Here are documentation links of the functions I used for reference:
0 Comments
See Also
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!