Matlab中轴刻度标签中的新行 [英] New line in axis tick labels in Matlab

查看:89
本文介绍了Matlab中轴刻度标签中的新行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Matlab的轴刻度标签中是否有换行符以产生多行刻度标签?

Is there a way to have a new line in an axis tick label in Matlab to produce a multiline tick label?

来自此处的两个建议对于其他文本元素似乎无效:

The two suggestions from here for other text elements don't seem to work:

set(gca,'xticklabel',{{'line1','line2'}}) 

失败,并且

set(gca,'xticklabel',{['line1' 10 'line2']}) 

set(gca,'xticklabel',{['line1' 13 'line2']}) 

忽略换行符或回车符.有什么想法吗?

ignore the newline or carriage return. Any ideas?

推荐答案

我不确定它已经存在多久了,但是至少在R2015b中,轴对象具有

I am not sure how long it has been around, but at least in R2015b the axes objects have a 'TickLabelInterpreter' property, which can be specified to set how the tick labels are interpreted. If you choose a LaTeX interpreter, it is possible to have multiline ticklabels quite easily by wrapping them in a tabular environment.

示例:

figure;
plot(rand(10,1));
%// Tick label with arbitrary number of lines in tabular environment
xtl = '\begin{tabular}{c} line 1 \\ line 2 \\ line 3\\ line 4\end{tabular}';
%// use the tick label at location 5 on the x axis
set(gca,'xtick', 5, 'XTickLabel', xtl, 'TickLabelInterpreter', 'latex');

输出:

当然,这里的缺点是您需要使用LaTeX解释器,该解释器会稍微改变图形的外观.但是我相信有些人(例如我)实际上更喜欢LaTeX解释的图形注释的外观!另外,您可以在标签中使用所需的任何其他LaTeX标记(等式).

Of course, the drawback here is that you need to use the LaTeX interpreter which somewhat changes the appearance of the figure. But I believe some people (such as me) actually prefer the way the LaTeX interpreted figure annotations look! As an added bonus, you can use whatever other LaTeX markup you desire (equations, etc.) in the labels.

这篇关于Matlab中轴刻度标签中的新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆