3个回答
展开全部
你这个有点儿小难度,只能采用代码画legend,参考如下:
clear ;
clc;
figure(1);
cxd = rand(10,6)*0.8; %%%%% 产生0到0.8的随机数
h2=plot(cxd);
set(h2(1),'LineStyle','-','LineWidth',2,'Color','b','Marker','o',...
'MarkerEdgeColor','b','MarkerFaceColor','b','MarkerSize',5)
set(h2(2),'LineStyle','-','LineWidth',2,'Color','m','Marker','o',...
'MarkerEdgeColor','m','MarkerFaceColor','m','MarkerSize',5)
set(h2(3),'LineStyle','-','LineWidth',2,'Color','r','Marker','o',...
'MarkerEdgeColor','r','MarkerFaceColor','r','MarkerSize',5)
set(h2(4),'LineStyle','-','LineWidth',2,'Color','c','Marker','o',...
'MarkerEdgeColor','c','MarkerFaceColor','c','MarkerSize',5)
set(h2(5),'LineStyle','-','LineWidth',2,'Color','k','Marker','o',...
'MarkerEdgeColor','k','MarkerFaceColor','k','MarkerSize',5)
set(h2(6),'LineStyle','-','LineWidth',2,'Color','g','Marker','o',...
'MarkerEdgeColor','g','MarkerFaceColor','g','MarkerSize',5)
%下面都是为了把图例放到合适的位置而设置的
hold on
x=[[1 1 4 4 7 7 ]+0.5;[1 1 4 4 7 7 ]+1.5];
y=[[9 8 9 8 9 8 ]./10+0.05;[9 8 9 8 9 8 ]./10+0.05];
h3=plot(x,y);
set(h3(1),'LineStyle','-','LineWidth',2,'Color','b')
set(h3(2),'LineStyle','-','LineWidth',2,'Color','m')
set(h3(3),'LineStyle','-','LineWidth',2,'Color','r')
set(h3(4),'LineStyle','-','LineWidth',2,'Color','c')
set(h3(5),'LineStyle','-','LineWidth',2,'Color','k')
set(h3(6),'LineStyle','-','LineWidth',2,'Color','g')
%以上是为了画图例线
hold on
x1=[[1 1 4 4 7 7 ]+1;[1 1 4 4 7 7 ]+1];
y1=[[9 8 9 8 9 8 ]./10+0.05;[9 8 9 8 9 8 ]./10+0.05];
h4=plot(x1,y1);
set(h4(1),'Marker','o','MarkerEdgeColor','b','MarkerFaceColor','b','MarkerSize',5)
set(h4(2),'Marker','o','MarkerEdgeColor','m','MarkerFaceColor','m','MarkerSize',5)
set(h4(3),'Marker','o','MarkerEdgeColor','r','MarkerFaceColor','r','MarkerSize',5)
set(h4(4),'Marker','o','MarkerEdgeColor','c','MarkerFaceColor','c','MarkerSize',5)
set(h4(5),'Marker','o','MarkerEdgeColor','k','MarkerFaceColor','k','MarkerSize',5)
set(h4(6),'Marker','o','MarkerEdgeColor','g','MarkerFaceColor','g','MarkerSize',5)
%以上是为了画图例的点
legends={'cxd1','cxd2','cxd3','cxd4','cxd5','cxd6'};
tx=[1 1 4 4 7 7 ]+1.8;
ty=[9 8 9 8 9 8 ]./10+0.05;
for i=1:6
text(tx(i),ty(i),legends{i});
end
%以上是为了设置图例中字的放置位置
xlim([1,10]);ylim([0,1]);
xlabel('x');ylabel('y');title('legend测试');
grid on;box off;
结果:
展开全部
legend排版没有什么好办法,只能分别构造两个legend,见下面的例子:
a=0:0.01:4*pi;
y1=100*sin(a);
y2=50*cos(a);
y3=20*sin(2*a);
y4=tan(a);
y5=log(a);
y6=tan(2*a);
y=[y1;y2;y3;y4;y5;y6];
figure
p=plot(a,y)
legend(p(1:3),'sin','cos','sin(2a)');
ah=axes('position',get(gca,'position'),'visible','off');
legend(ah,p(4:6),'tan','log','tan(2a)');
图出来以后,用鼠标将legend图框手动拖到合适的位置:
不喜欢有外框,可以关掉(legend boxoff)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
x = linspace(0,pi);
y1 = cos(x);
plot(x,y1)
hold ony2 = cos(2*x);
plot(x,y2)
y3 = cos(3*x);
plot(x,y3)
y4 = cos(4*x);
plot(x,y4)
hold off;
legend({'cos(x)','cos(2x)','cos(3x)','cos(4x)'},'Location','northwest','NumColumns',2)
在legend语句中加入'NumColumns',3 就可以变成三列了。
可参考网页链接
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询