How to write x-ticks in latex.

26 views (last 30 days)
Atom
Atom on 8 Nov 2022
Answered: Star Strider on 8 Nov 2022
How to write x-ticks in latex.
I tried with
xticklabels({'x_m','x_2'},'interpreter','latex')
But failed. Please suggest or modify the code so that I can get the desired xticklabels $x_m$ and $x_2$ at x=0.2,0.5 respectively in latex.
plot([.2 .2], [0 .35],'--k')
hold on
plot([.5 .5], [0 .35],'--k')
axis([0 1 0 .35]);
xticks([.2 .5])
xticklabels({'xm','x2'})
xlabel('$x\rightarrow$','FontSize',20,'interpreter','latex','FontWeight','normal','Color','k')
ylabel('$y\rightarrow$','FontSize',20,'interpreter','latex','FontWeight','normal','Color','k')

Accepted Answer

Star Strider
Star Strider on 8 Nov 2022
Try this —
plot([.2 .2], [0 .35],'--k')
hold on
plot([.5 .5], [0 .35],'--k')
axis([0 1 0 .35]);
xticks([.2 .5])
Ax = gca;
Ax.XAxis.TickLabels = {'$x_m$','$x_2$'}; % Changed
Ax.XAxis.TickLabelInterpreter = 'latex'; % Added
xlabel('$x\rightarrow$','FontSize',20,'interpreter','latex','FontWeight','normal','Color','k')
ylabel('$y\rightarrow$','FontSize',20,'interpreter','latex','FontWeight','normal','Color','k')
.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!