沒有在爲Matlab的傳說做這個內置的能力。您可以通過手動繪製線條來實現類似的效果。這使用了annotation arrow功能爲一個圖:
% plot some dummy data (not connected to the manual legend!
x = linspace(-1,1);
clf; hold on; grid on
% Set up linestyles and linecolors here so that they can be (at least
% slightly) linked between the plot and the manual legend.
linestyles = {'-', '--'};
linecolors = {'k', 'r'};
% plots
plot(x,x.^2,'linestyle',linestyles{1},'color',linecolors{1});
plot(x,x.^3,'linestyle',linestyles{1},'color',linecolors{2});
plot(x,x.^4,'linestyle',linestyles{2},'color',linecolors{1});
plot(x,x.^5,'linestyle',linestyles{2},'color',linecolors{2});
% scale the plot within the figure to leave room for legend
plotsize = [0.06, 0.20, 0.9, 0.75];
set(gca,'position', plotsize)
% x and y are original positions for the lines
x = 0.4; y = 0.1;
% dx and dy are length and vertical spacing of lines respectively
dx = 0.1; dy = 0.05;
% The main event: drawing (headless) text arrows, so that one of them can have
% a string properly which is your legend entry label. Use x,y,dx,dy for positioning
annotation('textarrow', [x,x+dx], [y,y], ...
'linestyle', linestyles{1}, 'color', linecolors{1}, 'textcolor', 'k', 'headstyle', 'none', ...
'string', 'Even functions ')
annotation('textarrow', [x+dx + 0.005,x+2*dx + 0.005], [y,y], ...
'linestyle', linestyles{2}, 'color', linecolors{1}, 'textcolor', 'k', 'headstyle', 'none')
annotation('textarrow', [x,x+dx], [y-dy,y-dy], ...
'linestyle', linestyles{1}, 'color', linecolors{2}, 'textcolor', 'k', 'headstyle', 'none', ...
'string', 'Odd functions ')
annotation('textarrow', [x+dx + 0.005,x+2*dx + 0.005], [y-dy,y-dy], ...
'linestyle', linestyles{2}, 'color', linecolors{2}, 'textcolor', 'k', 'headstyle', 'none')
結果:
![plot](https://i.stack.imgur.com/qmZzh.png)
注意該定位與歸一化的完成的值(0和1之間),因此它們與舒展圖。如果您的繪圖具有固定大小,處理像素可以更容易可視化,這可以通過在調整大小時更改各種圖形對象的參數來完成(請參閱上面關於註釋箭頭鏈接的文檔)。
有沒有辦法知道圖例本身的屬性?例如,圖例中繪製的線的大小,圖例的周圍框與線條本身之間的空間,......類似的東西,以便我至少可以獲得一個位置,從中可以繪製出像您這樣的註釋沒有。我無法自己找到它,但我想我有很多我不知道matlab,必須有一種方法來找到這些參數。 – mwoua
總之,我不這麼認爲。 – Wolfie