Matlab 二位绘图函数 bar pie 直方图等

一、简介

year=2018:2022;
pop=[0.8,0.68,0.98,0.86,0.7]
subplot(2,2,1)
plot(year,pop);
title('plot');
xlabel('year');
ylabel('Popluation(mil)')


subplot(2,2,2)
bar(year,pop);
title('bar');
xlabel('year');
ylabel('Popluation(mil)');

subplot(2,2,3)
area(year,pop);
title('area');
xlabel('year');
ylabel('Popluation(mil)');

subplot(2,2,4)
stem(year,pop);
title('system');
xlabel('year');
ylabel('Popluation(mil)')

 改进之后的代码:

year=2018:2022;
pop=[0.8,0.68,0.98,0.86,0.7]

func={@plot,@bar,@area,@stem}
for i=1:4
    subplot(2,2,i)
    fn=func{i};
    fn(year,pop);
    title('plot');
    xlabel('year');
    ylabel('Popluation(mil)')
end

ex2:

 

 

 

 

 

 

x=[1 2 3];
y=[2,4 2;11 21 8];
b=bar(x,y);

xtip=b(1).XEndPoints;
ytip=b(1).YEndPoints;
xla=string(b(1).YData);


xtip2=b(2).XEndPoints;
ytip2=b(2).YEndPoints;
xla2=string(b(2).YData);
text(xtip2,ytip2,xla2);

 

 

 直方图:

 圆饼图

 

 

>> p(2).BackgroundColor='red'

p = 

  1×10 graphics 数组:

    Patch    Text     Patch    Text     Patch    Text     Patch    Text     Patch    Text 
 

 

 

x=[0.1 0.2 0.3];
labels={'A','B','C','D'};
y2021=[50,0,100,97];
y2022=[80,10,180,71];
subplot(2,1,1);
pie(y2021);
legend(labels,'Location','best');

subplot(2,1,2);
pie(y2022);
legend(labels,'Location','best');

 坐标轴刻度:

 

 

 

 

x=linspace(0,10,10000);
y=exp(x);
y1=3.^x;
figure(1);
clf;

subplot(2,1,1);
plot(x,y,'-.',x,y1,'r-');
% semilogy(x,y);
% semilogx(x,y);
title('log');
ax=gca;
ax.YScale='log';
legend('exp(x)','3.^x');



subplot(2,1,2);
plot(x,y,'--',x,y1,'r-');
% semilogy(x,y);
% semilogx(x,y);
title('linear');
ax=gca;
ax.YScale='linear';
legend('exp(x)','3.^x');

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值