matlab二维画图函数汇总--论文,数学建模中使用

 一段代码对应相应的图形:

%matlab基本画图
clc
clear
x = linspace(-2*pi,2*pi,100);
y = sin(x);
%画出基本线条
plot(x,y);
%画出多条曲线
plot(x,sin(x),x,cos(x));

 

%根据矩阵画出线条
clc
clear
Y = magic(5)
figure
plot(Y)

%指定线形
clc
clear
x = 0:pi/100:2*pi;
y1 = sin(x);
y2 = sin(x-0.25);
y3 = sin(x-0.5);
figure
plot(x,y1,x,y2,'--',x,y3,':');

  

%指定线形颜色和标记
clc
clear
x = 0:pi/10:2*pi;
y1 = sin(x);
y2 = sin(x-0.25);
y3 = sin(x-0.5);
figure
plot(x,y1,'g',x,y2,'b--o',x,y3,'c*');

 

%在指定的数据点显示标记
clc
clear
x = linspace(0,10);
y = sin(x);
plot(x,y,'-o','MarkerIndices',1:5:length(y));

 

%指定线宽,标记大小和标记颜色
clc
clear
x = -pi:pi/10:pi;
y = tan(sin(x)) - sin(tan(x));

figure
plot(x,y,'--gs',...
    'LineWidth',2,...
    'MarkerSize',10,...
    'MarkerEdgeColor','b',...
    'MarkerFaceColor',[0.5,0.5,0.5])

 

%添加标题和轴标签
clc
clear
x = linspace(0,10,150);
y = cos(5*x);

figure
plot(x,y,'Color',[0,0.7,0.9]);
title('2-D Line Plot');
xlabel('x');
ylabel('cos(5x)');

 

%绘制持续时间并指定刻度格式
clc
clear
t = 0:seconds(30):minutes(3);
y = rand(1,7);

plot(t,y,'DurationTickFormat','mm:ss');

 

%指定线图的坐标区
clc
clear
ax1 = subplot(2,1,1);
x = linspace(0,3);
y1 = sin(5*x);
plot(ax1,x,y1);
title(ax1,'Top Subplot');
ylabel(ax1,'sin(5x)');

ax2 = subplot(2,1,2);
y2 = sin(15*x);
plot(ax2,x,y2);
title(ax2,'Botton Subplot');
ylabel(ax2,'sin(15x)');

 

%创建并修改线条
clc
clear
x = linspace(-2*pi,2*pi)
y1 = sin(x)
y2 = cos(x)
p = plot(x,y1,x,y2)

p(1).LineWidth = 2
p(2).Marker = '*'

%绘制图形
clc
clear
r = 2;
xc = 4;
yc = 3;
theta = linspace(0,2*pi);
x =r*cos(theta)+xc;
y =r*sin(theta)+yc;
plot(x,y);
axis equal

 

%其他画图函数
%条形图
clc
clear
close all
x = 1:10
y = rand(size(x))
bar(x,y)

 

%误差图
clc
clear
close all
x = linspace(0,2*pi,30)
y = sin(x)
e = std(y)*ones(size(x))
errorbar(x,y,e)
%fplot用来画出剧烈变化的图形
fplot(@(x)sin(1./x),[0.02,0.2]);

 

%极坐标图
clc
close all
clear
theta = linspace(0,2*pi)
r = cos(4*theta)
polarplot(theta,r)

clc
clear
x = randn(5000,1)
histogram(x,20)

%rose类似于hist,表达形式不一样
clc
clear
x = randn(1000,1)
polarhistogram(x)

%stairs画出阶梯图
clc
clear
x = linspace(0,10,50)
y = sin(x).*exp(-x/3)
stairs(x,y)

 

%stem画出针状图
clc
clear
x = linspace(0,10,50)
y = sin(x).*exp(-x/3)
stem(x,y)

 

%fill多边形画图
clc
clear
x = linspace(0,10,50)
y = sin(x).*exp(-x/3)
fill(x,y,'b')

 

%feather以复数画出数据
clc
clear
theta = linspace(0,2*pi,20)
z = cos(theta)+1i*sin(theta)
feather(z)

 

%compass和feather类似,箭头起点在原点
clc
clear
theta = linspace(0,2*pi,20)
z = cos(theta)+1i*sin(theta)
compass(z)

 

猜你喜欢

转载自blog.csdn.net/weixin_51229250/article/details/122660915