matlab linspace legend

linspace legend

linspace
生成线性间距向量

y = linspace(x1,x2)
y = linspace(x1,x2,n)

y = linspace(x1,x2) 返回包含 x1 和 x2 之间的 100 个等间距点的行向量。
y = linspace(x1,x2,n) 生成 n 个点。这些点的间距为 (x2-x1)/(n-1)。

linspace 类似于冒号运算符“:”,但可以直接控制点数并始终包括端点。“linspace”名称中的“lin”指示生成线性间距值而不是同级函数 logspace,后者会生成对数间距值。

clc,clear;
x = linspace(0,4*pi,10);
y = sin(x);
p = polyfit(x,y,7);

x1 = linspace(0,4*pi);
y1 = polyval(p,x1);
figure
plot(x,y,'go')
hold on
plot(x1,y1,'b')
hold off

clc,clear,close all;
x = linspace(0,1,5);
y = 1./(1+x);

p = polyfit(x,y,4);

x1 = linspace(0,2);
y1 = 1./(1+x1);
f1 = polyval(p,x1);

figure
plot(x,y,'o')
hold on
plot(x1,y1)
plot(x1,f1,'r--')
legend('y','y1','f1')

clc,clear,close all;
x = linspace(0,pi);
y1 = cos(x);
plot(x,y1,'g')

hold on 
y2 = cos(2*x);
plot(x,y2,'m')

legend('cos(x)','cos(2x)')

y3 = cos(3*x);
plot(x,y3,'DisplayName','cos(3x)')
hold off

legend('off')

clc,clear,close all;
tiledlayout(2,1)
y1 = rand(3);
ax1 = nexttile; 
plot(y1)

y2 = rand(5);
ax2 = nexttile; 
plot(y2)

legend(ax1,{'Line 1','Line 2','Line 3'})

clc,clear,close all;
x = linspace(0,pi);
y1 = cos(x);
plot(x,y1,'DisplayName','cos(x)')

hold on 
y2 = cos(2*x);
plot(x,y2,'DisplayName','cos(2x)')
hold off

legend

clc,clear,close all;
x = linspace(0,pi);
y1 = cos(x);
plot(x,y1)

hold on
y2 = 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)

clc,clear,close all;
tiledlayout(2,2);
nexttile
plot(rand(5))
nexttile
plot(rand(5))
nexttile
plot(rand(5))

lgd = legend;
lgd.Layout.Tile = 4;%版本问题

clc,clear,close all;
x = linspace(0,pi);
y1 = cos(x);
p1 = plot(x,y1);

hold on
y2 = cos(2*x);
p2 = plot(x,y2);

y3 = cos(3*x);
p3 = plot(x,y3);
hold off

legend([p1 p3],{'First','Third'})

clc,clear,close all;
x = linspace(0,pi);
y1 = cos(x);
plot(x,y1)

hold on
y2 = cos(2*x);
plot(x,y2)
hold off

lgd = legend('cos(x)','cos(2x)');
title(lgd,'Legend Title')

clc,clear,close all;
x = linspace(0,pi);
y1 = cos(x);
plot(x,y1)

hold on
y2 = cos(2*x);
plot(x,y2)
hold off

legend({'cos(x)','cos(2x)'},'Location','southwest')
legend('boxoff')

clc,clear,close all;
rdm = rand(4);
plot(rdm)

lgd = legend({'Line 1','Line 2','Line 3','Line 4'},'FontSize',12,'TextColor','m')

lgd.NumColumns = 2;
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值