如何为任何情节添加自定义图例?
例如:
figure(200)
plot(t1:k,Pexact(t1:k,1),'-xk');
plot(t1:k,xh(1,t1:k),'-sr');
然后我想用相同的代码添加图
hold on plot(t1:k,xh(1,t1:k),'-sb');
然后我想为所有三个地块添加一个图例
答案 0 :(得分:0)
if exist('hl','var')
clear hl
end
hold on
hl(1) = plot(t1,0,'-sr');
hl(2) = plot(t1,0,'-sb');
hl(3) = plot(t1,0,'-xk');
set(hl,'LineWidth',2);
set(hl,'Visible','off');
legend(hl,'SC-PF','PF','Truth',...
'Location','NorthWest');
答案 1 :(得分:0)
当我调出情节时,我更喜欢定义传奇。如果特定集合中缺少数据,或者您设置了条件,以便不是每次都绘制所有数据,则此方法更有意义。
figure(fig)
hold on
plot(t1:k,Pexact(t1:k,1),'-xk','DisplayName','SC-PF');
plot(t1:k,xh(1,t1:k),'-sr','DisplayName','PF');
plot(t1:k,xh(1,t1:k),'-sb','DisplayName','Truth')
legend(get(fig, 'Child'),'show')
legend('location','northwest')