MATLAB,Figure圖兩個Legend方法


  MATLAB2014版本之前可用copyobj復制但是2014 及以上版本無法繼續使用,所以進行了以下改動,以下版本可適應高版本;

具體數據不放了,關鍵步驟在下面標記了:

figure(1)
a1=plot(x1,f1);
hold on
a2=plot(x1,fs1);
hold on
a3=plot(x2,f2);
hold on
a4=plot(x2,fs2);
hold on
a5=plot(x3,f3);
hold on
a6=plot(x3,fs3);
a=[a1;a3;a5;a2;a4;a6];
xlabel('位移(mm)')
ylabel('力(N)')
%返回當前圖窗中的當前坐標區到ax1
ax1 = gca;

%ax2與ax1橫縱坐標范圍對應
ax2 = axes( 'Position',get(ax1,'Position'),'Visible','off');
%畫兩個legend
Leg1 = legend( ax1,a(1:3),'實驗-1','實驗-2','實驗-3','location','west' );
Leg2 = legend( ax2,a(4:6),'預測-1','預測-2','預測-3','location','east' );

   原因:2014以上版本只允許一個axes有一個legend ,要有兩個axes才能對應兩個legend,第二個axes與第一個axes相同,便可定義兩個legend


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM