Plot does not match with x tick label

조회 수: 3 (최근 30일)
Mevlana Jalaluddin Rumi
Mevlana Jalaluddin Rumi 2020년 12월 22일
편집: Cris LaPierre 2020년 12월 22일
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')

채택된 답변

Cris LaPierre
Cris LaPierre 2020년 12월 22일
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))
  댓글 수: 2
Mevlana Jalaluddin Rumi
Mevlana Jalaluddin Rumi 2020년 12월 22일
Hey, thanks for answering and yes your answer helped.
I was wondering if is it possible to display the actual value of the data in the x label (the plot used for the x label is an array t1=[06;07;08;09;10;15;16;17;20;21;22;23;24;27;28;29;30] ) and not display the x label's range.
Cris LaPierre
Cris LaPierre 2020년 12월 22일
편집: Cris LaPierre 2020년 12월 22일
It's possible, though very misleading. This is the data that is typically displayed on the Y axis. No one except for you will be able to properly interpret your figure.
x=1:5;
y=3*x;
plot(x,y)
xticks(x)
xticklabels(y)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Axis Labels에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by