Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab 两行上的X轴标签_Matlab_Plot_Label_Matlab Figure - Fatal编程技术网

Matlab 两行上的X轴标签

Matlab 两行上的X轴标签,matlab,plot,label,matlab-figure,Matlab,Plot,Label,Matlab Figure,我看不懂情节下面的文字。你知道怎么修吗 截图: 如果您对90度旋转文本没有问题,您可以尝试使用此代码,该代码基于非常有用的x标签旋转文本工具 代码 str = {'HS31'; 'HS31 (Ridotto)'; 'Dax85';'Dax85 (Ridotto)'; 'FTSE89';'FTSE89 (Ridotto)'; 'SP98';'SP98 (Ridotto)'; 'Nikkei22';'Nikkei225 (Ridotto)'; 'SP457';

我看不懂情节下面的文字。你知道怎么修吗

截图:

如果您对90度旋转文本没有问题,您可以尝试使用此代码,该代码基于非常有用的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');
带有一些随机数据的样本图

如果您同意对x标签文本进行下采样,例如,仅每隔一次显示一次 标签,在创建地物控制柄之前使用此选项-

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');
代码的其余部分保持不变。输出图如下所示-

如果仍然希望保持数据水平,则需要将标签数减少一个好的系数。在给定的示例案例中,
4
的系数起作用。代码中的更改是在声明
str
之后添加以下代码,当然还有对x-label旋转工具用法的注释-

str(1:2:end)={[]}
这里的技巧是对要跳过的x标签使用空单元格

结果-


Divakar的答案中缺少的实际上是一个包含两行(或更多行)的解决方案。您可以在某些位置使用文本框来模拟它

str1 = cell(1,numel(str));
str1(1:4:end) = str(1:4:end);
str = str1;
行数和一些间距参数必须手动设置。当图形最大化时,它看起来是这样的


您可以在标签内键入控制字符
\newline

您可以或使用基于
文本的定制解决方案(大致类似于)。如果我有一段时间,之前没有人这样做,我将写一个完整的例子。这里有另一个替代解决方案:你也有在每一秒标签的文字之前,包括标签。这可能没有必要。我认为更好的布局可能只是打印1:2:结束标签,并用另一种颜色给名为(Ridotto)的条上色。然而,我实际上更喜欢90度旋转的解决方案,因为标签文本仍然很长,两行可能不够。是的,我想我们需要根据具体情况来研究这些问题。你的解决方案很好,可能是OP实际要求的解决方案!我认为有不同的选择不会有什么坏处,对于给定的数据,在我看来,旋转的选择也会更好+1.
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)';};
bar(rand(26, 1));
% clear labels existing so far
set(gca, 'XTickLabel', {});

% parameters
spacing = 0.03; % between different rows of labels and between x-axis and label
rows = 2; % number of rows in staggered layout
heightAdjust = 0.1; % reduce height of figure to make space for vertically stacked labels

pos = get(gca,'Position');
set(gca, 'Position', pos+ [0 heightAdjust 0 -heightAdjust] )

ylim = get(gca, 'YLim');
for i = 1 : length(str) % for all labels
    % compute y position of label (depends on x, therefore staggered)
    y = ylim(1) - spacing - spacing * mod(i - 1, rows);
    % print text box at correct position to simulate label
    text('Units', 'Data', 'Position', [i, y], 'HorizontalAlignment', 'center', 'String', str(i));
end