组装许多曲线的图例 [英] Assemble Legend for Many Curves
问题描述
我需要为索引曲线组装一个Matlab/Octave图例,并且发现以下示例似乎运行良好:
I need to assemble a Matlab/Octave legend for indexed curves, and I found the following example which seems to work well:
legend(strcat("curve ", num2str(1:2)))
将标签曲线1"和曲线2"与给定的两条曲线相关联.但是,如果我需要添加其他非索引类型的曲线,则上述方法似乎不再起作用.
Associates the labels "curve 1" and "curve 2" with the two curves given. However, if I need to add a different, non-indexed type of curve, the method above seems not to work anymore.
legend(strcat("curve ", num2str(1:2)),"another curve")
在第二个示例中,第一条曲线具有图例["curve 1";曲线2"],第二条曲线获得图例的另一条曲线",而最后一条曲线没有图例.我认为这与图例解释输入的方式有关,但我无法解决它.
In the second example the first curve has for legend ["curve 1"; "curve 2"], and the second curve gets "another curve" for legend, while the last curve gets no legend. I think it has to do with the way legend interprets input, and I'm not able to get around it.
推荐答案
尝试预先将图例组装为单元格数组,然后将其用作图例输入.
Try assembling the legend as a cell array beforehand, and then using that as the legend input.
legendCell = cell.empty
for i = 1:2
legendCell{i} = ['curve' num2str(i)];
end
legendCell{end+1} = 'another curve';
legend(legendCell);
这篇关于组装许多曲线的图例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!