首页 > 代码库 > Matlab Plot 使用多个图例( legend )

Matlab Plot 使用多个图例( legend )

     用matlab 画图时,发现线太多,生成的图例,遮盖了曲线。于是想画成多个图例,然后可以自由拖动。

     废话不多说,1)代码; 2)效果。


%%%%%%%%%%%%  Code:

figure
%% ---- plot for maxtries performance
set(0,'DefaultTextFontName','Times',...
    'DefaultTextFontSize',16,...
    'DefaultAxesFontName','Times',...
    'DefaultAxesFontSize',12,...
    'DefaultLineLineWidth',1,...
    'DefaultLineMarkerSize',6);
% set(gcf,'Units','inches','Position',[0 0 6.0 4.0]);

% ======================= trace_1:
% --- 1 UB_ratio_EMF_10_A_trace_1
h10_1_tr1=plot(X_items, UB_ratio_EMF_10_A_trace_1, '-pk');
hold on
% --- 2 Real Ratio
h10_2_tr1=plot(X_items, Ratio_EMF_10_over_OPT_trace_1, '-.or');
hold on
h10_3_tr1=plot(X_items, LB_ratio_EMF_10_A_trace_1, '-^b');
hold on
% ======================= trace_1:~

% ======================= trace_2:
% --- 1 UB_ratio_EMF_10_A_trace_2
h10_1_tr2=plot(X_items, UB_ratio_EMF_10_A_trace_2, '-+k');
hold on
% --- 2 Real Ratio
h10_2_tr2=plot(X_items, Ratio_EMF_10_over_OPT_trace_2, '-.dr');
hold on
h10_3_tr2=plot(X_items, LB_ratio_EMF_10_A_trace_2, '->b');
hold on
% ======================= trace_2:~

% ======================= trace_3:
% --- 1 UB_ratio_EMF_10_A_trace_3
h10_1_tr3=plot(X_items, UB_ratio_EMF_10_A_trace_3, '-xk');
hold on
% --- 2 Real Ratio
h10_2_tr3=plot(X_items, Ratio_EMF_10_over_OPT_trace_3, '-.sr');
hold on
h10_3_tr3=plot(X_items, LB_ratio_EMF_10_A_trace_3, '-<b');
hold on
% ======================= trace_3:~
grid
ylim([0.5 2.5])
xlabel('Length of time-slot (seconds)')
ylabel('Ratio')
legend('U.B. ratio,\beta=10,Trace 1','Real ratio,\beta=10,Trace 1','L.B. ratio,\beta=10,Trace 1',0)
ah1_f10=axes('position',get(gca,'position'),...
            'visible','off');
legend(ah1_f10,[h10_1_tr2 h10_2_tr2 h10_3_tr2],'U.B. ratio,\beta=10,Trace 2','Real ratio,\beta=10,Trace 2','L.B. ratio,\beta=10,Trace 2',  ...
               'location','west', 0)
ah2_f10=axes('position',get(gca,'position'),...
            'visible','off');
legend(ah2_f10,[h10_1_tr3 h10_2_tr3 h10_3_tr3],'U.B. ratio,\beta=10,Trace 3','Real ratio,\beta=10,Trace 3','L.B. ratio,\beta=10,Trace 3',  ...
               'location','west', 0)


%  效果:


Davy_H

2014-7-10