绘图2
clc,clear;
close all;
x=linspace(0,2*pi,100);
plot(x,sin(x),'r',x,2*sin(x),'g',x,3*sin(x),'b')
result
clc,clear;
close all;
x=linspace(0,2*pi,100);
plot(x,sin(x),'r',x,2*sin(x),'g',x,3*sin(x),'b')
axis tight;
result
% x轴
x = 0:1/3000:1;
% 生成误差曲线
y = cos(tan(pi*x));
% 绘图
figure
% 分裂窗口为3行一列的3个子窗口
subplot(3,1,1)
plot(x,y)
title('\itcos(tan(\pix))')
% 坐标轴调整
subplot(3,1,2)
plot(x,y)
axis([0.45 0.55 -1 1]);
title('复杂函数的局部透视')
subplot(3,1,3)
plot(x,y)
axis([0.49 0.51 -1 1]);
title('复杂函数的深入局部透视')
semilogx函数使用半对数坐标,x轴为常用对数刻度,而y轴仍保持线性刻度。semilogy恰好和semilogx相反。
loglog函数使用全对数坐标,x、y轴均采用对数刻度。
clc,clear;
close all;
% x轴
x=0:0.5:5;
% y轴
y = exp(x);
% 绘图
figure
% 笛卡尔坐标系
subplot(4, 1, 1)
plot(x, y, 'r.')
title('笛卡尔坐标系')
% 半对数坐标系
subplot(4, 1, 2)
semilogx(x, y, 'g+')
title('x轴为对数坐标系')
subplot(4, 1, 3)
semilogy(x, y, 'b-')
title('y轴为对数坐标系')
% 对数坐标系
subplot(4, 1, 4)
loglog(x, y, 'ms','LineWidth',4)
title('对数坐标系')
result
clc,clear;
close all;
X = 1:3;
labels = {'Taxes','Expenses','Profit'};
explode = {'Profit'};
p = pie(X,labels)
t = p(6);
t.BackgroundColor = 'c';
t.EdgeColor = 'm';
t.FontSize = 14;
t = p(4);
t.BackgroundColor = 'g';
t.EdgeColor = 'm';
t.FontSize = 14;
t = p(2);
t.BackgroundColor = 'r';
t.EdgeColor = 'm';
t.FontSize = 14;
result
clc,clear;
close all;
x=[160 33 45 42 45];
% 分离显示设置
explode=[1 1 1 1 1];
% 绘图
figure()
cm=[0 1 0; 1 0 0; [122 16 228]/255; 0 0 1;0 1 1];
colormap(cm);
%colormap hsv
pie(x,explode,{'alimony','information costs','correspondence/telephone bill','clothes costs','others'})
title('饼图')
result
clc,clear;
close all;
%随机函数产生5*3的数组,对产生的数据取整
Y = round(rand(5,3)*10);
% 绘图
subplot(2,2,1)
bar(Y,'group')
title '分组二维垂直条形图'
%堆型二维垂直条形图
subplot(2,2,2)
bar(Y,'stack')
title('堆型二维垂直条形图')
%堆型二维水平条形图
subplot(2,2,3)
barh(Y,'stack')
title('堆型二维水平条形图')
%设定条形的宽度为1.5
subplot(2,2,4)
bar(Y,1.5)
title('重叠二维水平条形图')
result
clc,clear;
close all;
% 数据准备
y=[190 33 45 42 45];
x=1:5;
figure
bar(x,y)
title('柱状图');
set(gca,'xTicklabel',{'alimony','info','tele','clothes','others'})
result
累计分布
clc,clear;
close all;
pies = {'Chocolate','Apple','Pecan','Cherry','Pumpkin'};
votes = [35 50 30 5 80];
pareto(votes,pies,1)
ylabel('Votes')
clc,clear;
close all;
t=0:pi/50:2*pi;
x=8*cos(t);
y=16*sqrt(2)*sin(t);
z=16*sqrt(2)*sin(t);
plot3(x,y,z,'p');
title('三维空间闭合曲线(笛卡尔坐标系)');
text(0,0,0,'ori');
xlabel('X');
ylabel('Y');
zlabel('Z');
grid;
result
clc,clear;
close all;
% 数据准备
t=0:pi/10:pi;
x=sin(t);
y=cos(t);
[X,Y]=meshgrid(x,y);
z =X + Y;
figure
mesh (z,'FaceColor','r','EdgeColor','y')
grid
title('三维袈裟');