How can I edit x label so it doesn't overlap each other?
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (1)
Aashray
il 29 Ago 2025
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 Commenti
Vedere anche
Categorie
Scopri di più su Axis Labels in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!