www.gusucode.com > graphics 案例源码程序 matlab代码 > graphics/SpecifyAxesForLegendExample.m
%% Add Legend to Specific Axes % Create a figure with two subplots and return the two axes objects, |ax1| % and |ax2|. Plot random data in each subplot. Add a legend to the upper % subplot by specifying |ax1| as the first input argument to |legend|. y1 = rand(3); ax1 = subplot(2,1,1); plot(y1) y2 = rand(5); ax2 = subplot(2,1,2); plot(y2) legend(ax1,'Line 1','Line 2','Line 3')