的legend
函數將返回其第二個輸出參數處理傳奇。因此,您可以在圖例中將「虛擬」線繪製爲佔位符,在創建圖例時將手柄重新排序以將文本放在所需的位置,並相應地修改圖例對象。這裏有一個例子:
x = linspace(0, 2*pi, 100);
hl = plot(x, [sin(x); cos(x); tan(x); nan(size(x))].'); % Add a line of NaNs
axis([0 2*pi -4 4]);
[~, objH] = legend(hl([1 2 4 3]), 'sin', 'cos', 'junk', 'tan'); % Reorder handles
set(findobj(objH, 'Tag', 'junk'), 'Vis', 'off'); % Make "junk" lines invisible
pos = get(objH(3), 'Pos'); % Get text box position
set(objH(3), 'Pos', [0.1 pos(2:3)], 'String', 'also...'); % Stretch box and change text
![enter image description here](https://i.stack.imgur.com/leP2C.png)
不是說這是最好的解決方案,但也許你會發現它有用:[legtools](https://github.com/StackOverflowMATLABchat/legtools/)。 –