matlab图像绘制(进阶篇)

对数图形的绘制:

x = logspace(-1,1,100);
%在10^(-1)到10^(1)中取100个值
y = x.^2;
subplot(2,2,1); %用线性的方式画图
plot(x,y);
title('Plot');
subplot(2,2,2);
semilogx(x,y);%x轴取log (10^-1、10^0、10^1等间隔)
title('Semilogx');
subplot(2,2,3);
semilogy(x,y); %y 轴取log
title('Semilogy');
subplot(2,2,4);
loglog(x,y); %x轴和y 轴取Log
title('Loglog');

  >> set(gca,'XGrid','on'):

plotyy()  两个y轴:

clc;
clear;
x = 0:0.01:20;
y1 = 200*exp(-0.05*x).*sin(x);
y2 = 0.8*exp(-0.5*x).*sin(10*x);
[AX,H1,H2] = plotyy(x,y1,x,y2);
set(get(AX(1),'Ylabel'),'String','Left Y-axis');
set(get(AX(2),'Ylabel'),'String','Right Y-axis');
title('Labeling plotyy');
set(H1,'LineStyle','--');
set(H2,'LineStyle',':');

统计图

clc;
clear;
y = randn(1,1000);
%产生随机数
subplot(2,1,1);
hist(y,10);
%10个bins(就是会有10个柱形)
title('Bins = 10');
subplot(2,1,2);
hist(y,50);
title('Bins = 50');

hist是看整体的情况,bar是看个别的情况。

clc;
clear;
x = [1 2 5 4 8];
y = [x;1:5];
subplot(1,3,1); bar (x); title('A bargraph of vector x');
subplot(1,3,2); bar(y); title('A bargraph of vector y');
subplot(1,3,3); bar3(y); title('A 3D bargraph');

 

clc;
clear;
x = [1 2 5 4 8];
y = [x;1:5];
subplot(1,2,1); bar(y, 'stacked');
title('Stacked');
subplot(1,2,2); 
barh(y);
title('Horizontal');

 

【barh中h是horizontal的意思】

 barh(y,'stacked'):横向的:

画饼图:pie()

clc;
clear;
a = [10 5 20 30];
subplot(1,3,1); pie(a);
subplot(1,3,2); pie(a,[0,0,0,1]);    %[0,0,0,1]使最后一个扇形与其他分开;
subplot(1,3,3); pie3(a,[0,0,0,1]); %3D图

 极坐标图: polar()

clc;
clear;
x = 1:100; theta = x/10; r = log10(x);
subplot(1,4,1); polar(theta,r);
theta = linspace(0,2*pi); r = cos(4*theta);
subplot(1,4,2); polar(theta, r);
theta = linspace(0, 2*pi, 6); r = ones(1,length(theta));
subplot(1,4,3); polar(theta,r);
theta = linspace(0,2*pi); r = 1-sin(theta);
subplot(1,4,4); polar(theta,r);

 

 画正六边形:

theta = linspace(0,2*pi,7);
r = ones(1,length(theta));
polar(theta,r,'r-');

Stairs and Stem Charts:

 

x = linspace(0,4*pi, 40); y = sin(x);
subplot(1,2,1); stairs(y);
subplot(1,2,2); stem(y);

 

clc;
clear;

x = linspace(0,3*pi,100); y = sin(pi.*(x.^2)./4);
hold on ;
plot(y);
stem(y);
set(gca,'XLim',[0,100]);
set(gca,'XTickLabel',{'0','1','2','3','4','5','6','7','8','9','10'});
hold off;

 

(有待改进);

Boxplot和Error Bar:

Error Bar的意义:生活中的数值存在一定范围内发误差。

fill()在某区域填色:

颜色

imagesc(): 

 

[x,y] = meshgrid(-3:.2:3,-3:.2:3);
z = x.^2+x.*y +y.^2; surf(x,y,z); box on;
set(gca,'FontSize',16); zlabel('z');
xlim([-4 4]); xlabel('x'); ylim([-4 4]); ylabel('y');

【将颜色作为另外一个维度】 

%命令行输入:
imagesc(z); xlabel square; xlabel('x'); ylabel('y');

 

colorbar;

 

colormap(hot);%指定颜色的风格

 

colormap(cool);

colormap(gray)

 

a = colormap(prism);

 

【a就是一个颜色矩阵】 

>> a

a =

    1.0000         0         0
    1.0000    0.5000         0
    1.0000    1.0000         0
         0    1.0000         0
         0         0    1.0000
    0.6667         0    1.0000
    1.0000         0         0
    1.0000    0.5000         0
    1.0000    1.0000         0
         0    1.0000         0
         0         0    1.0000
    0.6667         0    1.0000
    1.0000         0         0
    1.0000    0.5000         0
    1.0000    1.0000         0
         0    1.0000         0
         0         0    1.0000
    0.6667         0    1.0000
    1.0000         0         0
    1.0000    0.5000         0
    1.0000    1.0000         0
         0    1.0000         0
         0         0    1.0000
    0.6667         0    1.0000
    1.0000         0         0
    1.0000    0.5000         0
    1.0000    1.0000         0
         0    1.0000         0
         0         0    1.0000
    0.6667         0    1.0000
    1.0000         0         0
    1.0000    0.5000         0
    1.0000    1.0000         0
         0    1.0000         0
         0         0    1.0000
    0.6667         0    1.0000
    1.0000         0         0
    1.0000    0.5000         0
    1.0000    1.0000         0
         0    1.0000         0
         0         0    1.0000
    0.6667         0    1.0000
    1.0000         0         0
    1.0000    0.5000         0
    1.0000    1.0000         0
         0    1.0000         0
         0         0    1.0000
    0.6667         0    1.0000
    1.0000         0         0
    1.0000    0.5000         0
    1.0000    1.0000         0
         0    1.0000         0
         0         0    1.0000
    0.6667         0    1.0000
    1.0000         0         0
    1.0000    0.5000         0
    1.0000    1.0000         0
         0    1.0000         0
         0         0    1.0000
    0.6667         0    1.0000
    1.0000         0         0
    1.0000    0.5000         0
    1.0000    1.0000         0
         0    1.0000         0

 

 

x = [1:10; 3:12; 5: 14];
imagesc(x);
colorbar;

 colormap(winter)

推荐博客:https://blog.csdn.net/weixin_42943114/article/details/81811556

3D画图:

plot3()只是线的指令,不会形成面。

x = 0:0.1:3*pi; z1 = sin(x);z2 = sin(2*x); z3 = sin(3*x);
y1 = zeros(size(x)); y3 = ones(size(x)); y2 = y3./2;
plot3(x,y1,z1,'r',x,y2,z2,'b',x,y3,z3,'g'); grid on;
xlabel('x-axis'); ylabel('y-axis'); zlabel('z-axis');

 

 

 

 

 

 

角度:

(可以从不同的角度看) 

 

光线:

 

 

【后面实在没有耐心了,码住下次好好仔细地看,https://www.bilibili.com/video/av14503445/?p=6】 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值