一、简介
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');