필터 지우기
필터 지우기

Unable to format fractions in xticklabels

조회 수: 4 (최근 30일)
Brilliant Purnawan
Brilliant Purnawan 2020년 11월 7일
댓글: Ameer Hamza 2020년 11월 7일
Hi, so I'm trying to write a fraction in 'xticklabels', I already tried to write
$\frac{a}{b}$
but it doesn't seem to work, any suggestions? Code section is given below:
figure(2);
plot(y(:,3),y(:,4));
xticks([-pi -3*pi/4 -pi/2 -pi/4 0 pi/4 pi/2 3*pi/4 pi])
xticklabels({'-\pi','$\frac{-3\pi}{4}$','-\frac{\pi}{2}','-\pi/4','0','\pi/4','\pi/2','3\pi/4','\pi'})
title('Angular Velocity Graph')
xlabel('Angle (rad)')
ylabel('Angular Velocity (rad s^{-1})')

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 11월 7일
You need to use latex interpreter. Following shows how to do that
figure(2);
ax = axes();
plot(y(:,3),y(:,4));
xlim([-pi pi])
xticks([-pi -3*pi/4 -pi/2 -pi/4 0 pi/4 pi/2 3*pi/4 pi])
xticklabels({'$-\pi$','$\frac{-3\pi}{4}$','$-\frac{\pi}{2}$','$-\pi/4$','$0$','$\pi/4$','$\pi/2$','$3\pi/4$','$\pi$'})
ax.XAxis.TickLabelInterpreter = 'latex';
title('Angular Velocity Graph')
xlabel('Angle (rad)')
ylabel('Angular Velocity (rad s^{-1})')
  댓글 수: 2
Brilliant Purnawan
Brilliant Purnawan 2020년 11월 7일
Cheers, it worked perfectly
Ameer Hamza
Ameer Hamza 2020년 11월 7일
I am glad to be of help!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Plot Customization에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by