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

1 次查看(过去 30 天)
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

采纳的回答

Wan Ji
Wan Ji 2021-8-29
Just use
xticklabels({'\$1\$','','\$2\$','','\$3\$','','\$4\$','','\$5\$',''});
rather than
xticklabels({'$1$','','$2$','','$3$','','$4$','','$5$',''});
  2 个评论
Wan Ji
Wan Ji 2021-8-29
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));

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Labels and Annotations 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by