Matlab画图 包含多个legend

来源:互联网 发布:惠普1513驱动for mac 编辑:程序博客网 时间:2024/05/16 10:12

没时间闲扯了,直接上代码吧。

x = 0:0.01:3;y1 = sin(x);y2 = sin(x).^2;y3 = sin(x).^sin(x);y4 = cos(x).*sin(x);plotsc{1} = 'ph(i) = plot(x, y1); hold on;';plotsc{2} = 'ph(i) = plot(x, y2); hold on;';plotsc{3} = 'ph(i) = plot(x, y3); hold on;';plotsc{4} = 'ph(i) = plot(x, y4); hold on;';figure;for i = 1:numel(plotsc)  eval(plotsc{i});endlegendsc = {'y_1', 'y_2', 'y_3', 'y_4'};lg1 = legend(ph(1:2), legendsc(1:2), 'Location', 'SouthWest');ah=axes('position',get(gca,'position'), 'visible','off');lg2 = legend(ah, ph(3:4), legendsc(3:4));lg2.Position = lg1.Position;lg2.Position(1) = lg1.Position(1)+lg1.Position(3)+0.02;

效果如下:
这里写图片描述

0 0
原创粉丝点击