【绘图】matlab绘制图形

Command

clear;

close all;		% 关闭所有图形窗口

clc;		% 清除命令行窗口中的数据

clf;		% 清除当前figure中的图形

图形规范

methodexplain
legend('')添加图例
axis([-inf,inf,0,inf])规定坐标系范围
grid添加轴网格线
pause()停顿时间(秒)
subplot()控制子图

绘图函数概览

MATLAB二维绘图工具

在这里插入图片描述

MATLAB三维绘图工具

在这里插入图片描述

如何动态更新显示图形

f1 = figure;
set(0,'CurrentFigure',f1);

xx = linspace(0,10);

for i = 1:100
	set(0,'CurrentFigure',f1);
	clf;
    plot(xx(1:i),sin(xx(1:i)),'k-');
    grid;
    pause(0.1);
end

plot

多条线展示

close all;
xx = [0:0.2:10];

figure;

hold on;
plot(xx,sin(xx),'bo');
plot(xx,cos(xx),'r*-');
plot(xx,zeros(1,length(xx)),'k--');

legend('sin','cos','0');
figure;

a = zeros(6,20);
for i=1:5
    a(i,:) = i;
end

hold on;
plot(a(1,:),'r-+');
plot(a(2,:),'g-o');
plot(a(3,:),'b-*');
plot(a(4,:),'k-.');
plot(a(5,:),'c-x');
plot(a(6,:),'y-p');
legend('0','1','2','3','4','5');
hold off;
title('example');

画一个矩形

figure;
a = [-1,1,1,-1,-1;-1,-1,1,1,-1];

hold on;
plot(a(1,:),a(2,:),'--k');
hold off;
axis([-2,2,-2,2]);

boxplot

box显示的分别为最小值、下四分位数、中位数、上四分位数、最大值

figure;
a = randn(5,10);

boxplot(a);

scatter

控制每个点的颜色

figure;

xx = rand(1000,1)*100;
yy = rand(1000,1)*100;

ind = randperm(1000);
color = zeros(1000,3);
color(ind(1:500), 1) = 1;

scatter(xx,yy,[],color,'.');      % []控制大小,这个参数位置必须占住,默认为36
grid;

直方图 bar

累加直方图

figure;

a = zeros(6,20);
for i=1:5
    a(i,:) = i;
end

bar(a','stacked');
legend('0','1','2','3','4','5');

title('example');

数据分布 histogram

这个命令在调试的时候很方便啊

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值