没有在为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')
结果:
注意该定位与归一化的完成的值(0和1之间),因此它们与舒展图。如果您的绘图具有固定大小,处理像素可以更容易可视化,这可以通过在调整大小时更改各种图形对象的参数来完成(请参阅上面关于注释箭头链接的文档)。
有没有办法知道图例本身的属性?例如,图例中绘制的线的大小,图例的周围框与线条本身之间的空间,......类似的东西,以便我至少可以获得一个位置,从中可以绘制出像您这样的注释没有。我无法自己找到它,但我想我有很多我不知道matlab,必须有一种方法来找到这些参数。 – mwoua
总之,我不这么认为。 – Wolfie