How to put latex in Xtick label? (Matlab 2015b)
12 次查看(过去 30 天)
显示 更早的评论
How can I have latex \mu and \mu_2 on the dotted lines Xtick? No other Xtick is necessary.
clc;
clear all;
mu=0;
mu2=4;
sigma=1;
x=linspace(mu-4*sigma, mu+4*sigma, 10000);
x2=linspace(mu2-4*sigma, mu2+4*sigma, 10000);
m_x = [mu mu2];
m_y = [0 0];
figure;
set(gcf,'units','inches','renderer', 'painters');
pos = get(gcf,'pos');
set(gcf,'Units','inches',...
'Position',[pos(1) pos(2) 3.5 2]);plot(x, normpdf (x,mu,sigma),'blue');
hold all;
plot(x2, normpdf (x2,mu2,sigma),'green');
plot(m_x, m_y,'red','LineWidth',3);
yL=get(gca,'YLim');
SP=0;
SP2=4;
line([SP SP],yL,'color','k','LineStyle',':');
line([SP2 SP2],yL,'color','k','LineStyle',':');
hold off
0 个评论
采纳的回答
Star Strider
2016-1-10
I don’t see where you’re defining them, but to invoke the LaTeX interpreter, use the name-value pair 'Interpreter','latex' in whatever call you want to use it in.
6 个评论
Star Strider
2016-1-11
I’ve not ever attempted multi-line tick labels, so I would have to experiment as well. Reverting to the text function (the typical approach prior to R2014b) to do what you want seems the best option.
I am somewhat surprised that LaTeX doesn’t offer a way to do multi-line labels, since TeX is a subset of LaTeX, and LaTeX is usually more powerful.
You’ve raised a number of significant issues in your post and explained them thoroughly, so I suggest you bring it to the attention of MathWorks Tech Support. Choose the ‘bug report or enhancement request’ option, and include a link to this thread with an introductory explanation. Have MATLAB open and run ver in the Command Window first.
Marc B
2016-11-15
编辑:Marc B
2016-11-15
If you want to have multiple lines in your TickLabels, you must put everything in a \parbox environment:
ax.TickLabelInterpreter='latex';
ax.XTickLabel={'\parbox{4em}{line \#1 \\ line \#2}'};
This produces the following output:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/185771/image.png)
I have not managed to get LaTeX colors working. It only seems to be working in TeX:
ax.TickLabelInterpreter='tex';
ax.XTickLabel={'\color{red}RED','\color{blue}BLUE'};
The output of this is:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/185772/image.png)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!