两行的X轴标签 [英] X-axis label on two rows

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

问题描述

str = {'HS31'; 'HS31 (Ridotto)';
    'Dax85';'Dax85 (Ridotto)';
    'FTSE89';'FTSE89 (Ridotto)';
    'SP98';'SP98 (Ridotto)';
    'Nikkei22';'Nikkei225 (Ridotto)';
    'SP457';'SP457 (Ridotto)';
    'Russ1318';'Russ1318 (Ridotto)';
    'Russ2151';'Russ2151 (Ridotto)';
    'Eurostoxx';'Eurostoxx (Ridotto)';
    'Ftse';'HS31 (Ridotto)';
    'Mibtel';'Mibtel (Ridotto)';
    'SP';'SP (Ridotto)';
    'Nasdaq';'Nasdaq (Ridotto)';

};
h=figure;
bar(t);
set(gca, 'XTickLabel',str, 'XTick',1:numel(str))

saveas(h, 'Backtesting/computing_time.png');

我看不懂情节下方的文字.你知道如何解决吗?

I can't read the text below the plot. Do you know how to fix it?

截屏: https://www.dropbox.com/s/g43iegh4oeng3kf/computing_time .png

推荐答案

如果您可以将文本旋转90度,可以尝试使用基于非常有用的x标签旋转文本工具的此代码,该工具可用 here

If you are okay with 90 degrees rotated text, you may try this code that is based on a very useful x-label rotating text tool, available here

代码

h=figure;
bar(randi(9,26,1),'EdgeColor','g') %// Assumed random data for demo
set(gca, 'XTickLabel',str, 'XTick',1:numel(str))
xticklabel_rotate([],90,str);%% File-exchange code %// xlabel text rotated
saveas(h, 'computing_time.png');

带有一些随机数据的样本图

如果您可以对x-label文本进行下采样,例如,仅显示其他所有 标签,请在创建图形手柄之前使用此权限-

If you are okay with down-sampling the x-label text, i.e. for example show only every other label, use this right before creating the figure handle -

str(1:2:end)={[]}

其余代码保持不变.输出图看起来像这样-

Rest of the code stays the same. The output plot would look like this -

如果您仍然希望保持数据水平,则需要对标签数量进行适当的下采样.在给定的示例中,系数4起作用.代码中的更改是在声明str之后,当然在注释了x标签旋转工具的用法之后,添加了以下代码-

If you still want to keep the data horizontal, you need to downsample the number of labels by a good factor. In your given sample case, a factor of 4 worked. The changes in the code is adding the following code right after declaring str and of course commenting the x-label rotating tool usage -

str1 = cell(1,numel(str));
str1(1:4:end) = str(1:4:end);
str = str1;

这里的窍门是对要跳过的x标签使用空单元格.

The trick here is to use empty cells for the x-labels that you want to skip.

结果-

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

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