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})')

采纳的回答

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})')

更多回答(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