How can I use '$...$' Environment in xticklabel with matlab2tikz?

1 view (last 30 days)
Hello,
I am generating a tikzpicture with following Code:
X = 1:1:10;
Y = sin(X);
plot(X,Y);
xticks(X);
xticklabels({'$1$','','$2$','','$3$','','$4$','','$5$',''});
cleanfigure;
matlab2tikz('testfig.tex', 'showInfo', false);
the generated lines for the xticklabels are: (Full Code attached)
xtick={1,2,3,4,5,6,7,8,9,10},
xticklabels={{\$1\$},{},{\$2\$},{},{\$3\$},{},{\$4\$},{},{\$5\$},{}},
Is there a way to tell matlab2tikz, not to interpret the text and exchange $ with \$ but just take it as is?
The compiled Picture looks like this:
For the Y-axis, math font is used, but as labels are often text, for the X-axis the normal text font style is used, why I tried with $$ environment.
So my original Problem is simply, that I dont want every ticklabel to be printed, but have it both in math font style.
I appreciate any help or workaround for this problem. Probably I am missing something as these are my first tries with this package.
Simon

Accepted Answer

Wan Ji
Wan Ji on 29 Aug 2021
Just use
xticklabels({'\$1\$','','\$2\$','','\$3\$','','\$4\$','','\$5\$',''});
rather than
xticklabels({'$1$','','$2$','','$3$','','$4$','','$5$',''});
  2 Comments
Wan Ji
Wan Ji on 29 Aug 2021
The tiks and ticklabel can be written in
x_tick = X(1:2:end);
xticks(x_tick);
xticklabels(arrayfun(@(i)['\$',num2str(x_tick(i)),'\$'],1:length(x_tick),'uniform',0));

Sign in to comment.

More Answers (0)

Categories

Find more on Labels and Annotations in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!