Unable to format fractions in xticklabels
조회 수: 4 (최근 30일)
이전 댓글 표시
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})')
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/405855/image.png)
댓글 수: 0
채택된 답변
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Plot Customization에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!