学习笔记(17):四十九课时精通matlab数学建模-精通matlab绘图

立即学习:https://edu.csdn.net/course/play/25039/288885?utm_source=blogtoedu

%%

1.一元函数

clear all;

x=-2:0.1:4;

figure;

plot(x,humps(x));

title('plot');

figure;

fplot(@humps,[-2,4])   %更加光滑

title('fplot');

2.

clear all;

figure;

fplot('[1/x,sin(x),cos(x)]',2*pi*[-1 1 -1 1]; %同时画三个图

legend('1/x','sin(x)','cos(x)');  %做一个标注

 

%% 极坐标绘图

clear all;

figure;

ezpolar('sin(8*x),cos(8*x)',[0,pi]);

 

%%

函数的三维网格图

ezmesh('x.*exp(x.^2-y.^2);

 

%%

带有等值线的三维网格图

ezmeshc('x.*exp(x.^2-y.^2);

 

%%

ezcontour %符号函数的等值线图

 

%%

ezsurf % 三维彩色曲面图

 

%%

ezsurfc  %带有等值线的三维彩色曲面图

 

matlab基本绘图元素

3. 

clear all;

t=0.1:0.02:2*pi;  %自变量范围

figure;

plot(t,sin(t),'r:');  %红色

hold on;

plot(t,cos(t));

xtable{'x'};  %横坐标标签

xtable{'x'};  %纵坐标标签

title{'plot'};  %题目

4.

clear all

y=magic(4); %%4行4列的矩阵

figure;

plot(y);  %对每一列绘制一条线,默认颜色不同

5.

clear all;

x=0:0.1:16;

y=sin(x);

figure;

plot(x,y);

6.

plot(x,y,'r-.*);   %线型进行设置

plot(x,y,'g:^');

7.

plot(x,y,'--rs','LineWidth',1,‘Markeredgecolor','k','markersize',4);

8.

matlab子图绘制和坐标轴控制

clear all;

x=pi:pi/20:pi;

figure;

subplot(2,1,1);

plot(x,sin(x),'r--');

subplot(2,1,2);

plot(x,cos(x),'b:*);

9.

subplot(2,2,1);

plot(x,sin(x),'r-');

subplot(223);

plot(x,cos(x),'h:*');

subplot(2,2,[2 4]) %两个图合并

10.

axis  %%设置坐标轴 获取当前坐标轴

axis([-1 1 -2 2]);  %%设置坐标轴显示范围

axis off 不再显示横纵坐标

 

matlab网格线和边框设置

11.

clear all;

i=0.01:0.01:28pi;

figure;

plot(i,sin(i));

axis([0 2*pi -1 1]);

grin on %显示网格线

12.

box  %打开边框

box off %关闭边框

 

坐标轴的缩放

13.

zoom on %坐标放大

14.

zoom xon %x轴放大

 

matlab绘图中级技巧

15.

图的拖拽

pan on; %打开拖拽功能

16.

datacursormode.on  %获取数据点

17.

绘制直线

line(x,y);

18.

极坐标绘图

solar(x,y,'--r');  

19.

双Y轴绘图

clear all;

x=0.1:0.1:2*pi;

y=sin(x);

z=10.^x;

figure;

plotyy(x,y,x,z);

 

图形的编辑操作

20.

matlab坐标轴标题和图例

xlabel('\it横轴标题’,‘fontname','宋体’);

xlabel('纵轴标题‘,’fontname','宋体‘,’rotation',-90);

21.

图例

legend('sin(x)','cos(x));

legend boxoff %隐藏图例的边框set(gca,'XTick',[0 pi 2*pi],'XTicklabel',{‘0’,‘pi','2pi'}];

 

文本框标注

22.

text(pi,sin(pi),'\leftarrow,sin(\pi)=0');

gtext('y=sin(x)','fontsize',10)  %任意位置可以

 

饼状图

23.

figure;

x=[0.2 0.3 .0.2];

subplot(121);

pie(x);

subplot(122);

y=[0.1 0.2 0.3 0.2 0.1];

explode=[0 0 1 0 0] %第三个突出

pie(y,explode);

24.

绘制直方图

figure;

x=randn(500,1);   %标准正太分布

subplot(121);

hist(x); %默认10个柱子

subplot(122);

y=randn(800,1);

hist(y,-4:-.1:4) %

25.

散点图

scatter(x,y.[],[1 0 0],'fill') %散点的颜色和填充

26.

火柴杆图

clear all

x=0.1:0.5:5*pi;

y=sin(x);

figure;

stem(x,y,'r');

27.

阶梯图

stairs(x,y,'r');

28.

罗盘图

compass(x,y,'r');

29.

羽毛图

feather(x,y);

30.

彗星图

comet(x,y)

 

三维图的绘制

1.

figure;

surf(x,y,z);  %三维图的绘制函数

view([55 75]);   %设置视角

colormap('cool');   %设置颜色

 shadng interp;

light('position',[1 0.4 0.4]);  %设置光照

axis square;   %坐标轴设置

xlabel('x');   %图形标注

2.

三维网状图

pie3(x);

3.

三维散点图

scatter3(x,y,z,'r','filled')   %绘制三维散点图

4.

绘制三维火柴杆图

stem3(x,y,z,'r','filled')  

comet3(x,y,z)

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值