我想在MATLAB中创建一个具有以下功能的图:
['string1','string2','string3','string4']
['sub1','sub2']
但是我希望它们能够显示在主弦上方,这样就可以使它们成为一个字符串' ?我希望你知道我的意思。 我想,也许有可能用茎图来实现这一点。然后我会在每个子串上有3个茎。每个字符串都有6个字符串。什么图表最适合完成此任务?
答案 0 :(得分:1)
您可以使用text命令获取x轴上的字符串
stem(rand(4,1));
set(gca, 'XTick', [1:4], 'XTickLabel', cell(10,1), 'YLim', [0 1]);
text(1, -.05, {'above string 1', 'above string 1', 'string 1'}, 'FontSize', 10, 'HorizontalAlignment', 'Center');
text(2, -.05, {'above string 2', 'above string 2', 'string 2'}, 'FontSize', 10, 'HorizontalAlignment', 'Center');
text(3, -.05, {'above string 3', 'above string 3', 'string 3'}, 'FontSize', 10, 'HorizontalAlignment', 'Center');
text(4, -.05, {'above string 4', 'above string 4', 'string 4'}, 'FontSize', 10, 'HorizontalAlignment', 'Center');
要从y轴绘制茎,您可以使用view命令旋转绘图框,如下所示:
% plot some data
stem([1:3], 'LineWidth', 2);
% set the x axis which will be the y axis after the rotation
set(gca, 'XLim', [1 3], 'XTick', [1:3], 'XTickLabel', cell(3,1));
text(1.1, -.25, {'another y string 1', 'above y string 1', 'y string 1'}, 'FontSize', 10, 'HorizontalAlignment', 'Center');
text(2, -.25, {'another y string 2', 'above y string 2', 'y string 2'}, 'FontSize', 10, 'HorizontalAlignment', 'Center');
text(3, -.25, {'another y string 3', 'above y string 3', 'y string 3'}, 'FontSize', 10, 'HorizontalAlignment', 'Center');
% set the y axis which will be the x axis after the rotation
set(gca, 'YLim', [0 3], 'YTick', [1:4], 'YTickLabel', cell(10,1));
text(0.9, 0, {'above string 1', 'above string 1', 'string 1'}, 'FontSize', 10, 'HorizontalAlignment', 'Center');
text(0.9, 1, {'above string 2', 'above string 2', 'string 2'}, 'FontSize', 10, 'HorizontalAlignment', 'Center');
text(0.9, 2, {'above string 3', 'above string 3', 'string 3'}, 'FontSize', 10, 'HorizontalAlignment', 'Center');
text(0.9, 3, {'above string 4', 'above string 4', 'string 4'}, 'FontSize', 10, 'HorizontalAlignment', 'Center');
% rotate the view
view(90,-90)