matlab:绘图(1)

学习素材:MATLAB教程_台大郭彦甫(14课)原视频补档

MATLAB教學 - 05初阶绘图_哔哩哔哩_bilibili

(部分素材使用视频截图)

目录

一、plot()

 1.窗口元素

 2.plot(x,y,’str’)

3.lenged() 

 4.titile()  and  label()

5. text() and annotation()

 6.例题一

 二、Figure AdjustMent

 1.查看图像属性

 2.XLim、YLim、FontSize、XTick、XTickLabel、FontName

(1).XLim\YLim

 (2).FontSIze字体大小

 (3)XTick/XTickLabel

 (4).FontName

 三、Line Specification

四、图像中点的设置

1.基本属性

 2.例题2

 五、绘制多个图像

 六、Position()间距

 七、Subplot()

 八、常用属性

 九、存储

1.saveas

 2.Print 高解析度

十、属性编辑器


一、plot()

会把旧的图形用新的图形清除掉

>> hold on
>> plot(cos(0:pi/20:2*pi));
>> plot(sin(0:pi/20:2*pi));
>> hold off

 1.窗口元素

 2.plot(x,y,’str’)

hold on
plot(cos(0:pi/20:2*pi),'or--');
plot(sin(0:pi/20:2*pi),'xg:');
hold off

3.lenged() 

 

X=0:0.5:4*pi;
y=sin(x);
h=cos(x);
w=1./(1+exp(-x));
g=(1/(2*pi*2)^0.5).*exp((-1.*(x-2*pi).^2)./(2*2^2));
plot(x,y,'bd-',x,h,'gp:',x,w,'ro-',x,g,'c^-');
legend('sin(x)','cos(x)','Sigmoid','Gauss function');

 4.titile()  and  label()

 

x=0:0.1:2*pi;
y1=sin(x);
y2=exp(-x);
plot(x,y1,'--*',x,y2,':o');
xlabel('t=0 to 2\pi');%\pi字源Π
ylabel('values of sin(t) and e^{-x}');%{-x}字源
title('Function Plots of sin(t) and e^{-x}');
legend('sin(t)','e^{-x}');

5. text() and annotation()

积分符号:\int

\int_{0}^{2}下标是0,上标是2

\sin宏命令,输出斜体的sin

Linspace 生成线性距离向量

y = linspace(x1,x2) 返回包含 x1 和 x2 之间的 100 个等间距点的行向量。

y = linspace(x1,x2,n) 生成 n 个点。这些点的间距为 (x2-x1)/(n-1)。

Text

向数据点添加文本描述 - MATLAB text - MathWorks 中国

Annotation

创建注释 - MATLAB annotation - MathWorks 中国

>> x = linspace(0,3);
>> y=x.^2.*sin(x);
>> plot(x,y);
>> line([2,2],[0,2^2*sin(2)]);
>> str = '$$\int_{0}^{2} x^2\sin(x) dx $$';
>> text(0.25,2.5,str,'Interpreter','latex');
%起点为[0.25,2.5]
%使用 LaTeX 标记解释字符
>> annotation('arrow','X',[0.32,0.5],'Y',[0.6,0.4]);%[0.32,0.5]:
%x坐标从整个图形的32%的地方到50%的地方(从左到右)
%[0.6,0.4]:y坐标从60%的地方到40%的地方(从上到下)

 6.例题一

>> t=linspace(1,2);
y=t.^(2);
g=sin(2.*pi.*t);
>> plot(y);
>> plot(y,'k');
>> hold on
>> plot(g,'or');
>> hold off
>> title('Mini Assignment #1');
>> xlabel('Time(ms)');
>> ylabel('f(t)');
>> legend('t^{2}','sin(2\pi t)');
>> legend('t^{2}','sin(2\pit)');

 

legend('t^{2}','sin(2\pit)','Location','northwest');

 二、Figure AdjustMent

 1.查看图像属性

 x= linspace(0,2*pi,1000);
>> y=sin(x);
>> plot(x,y);
>> h=plot(x,y);
>> get(h)

输出: 

AlignVertexCenters: off

            Annotation: [1×1 matlab.graphics.eventdata.Annotation]

          BeingDeleted: off

            BusyAction: 'queue'

         ButtonDownFcn: ''

              Children: [0×0 GraphicsPlaceholder]

              Clipping: on

                 Color: [0 0.4470 0.7410]

             ColorMode: 'auto'

           ContextMenu: [0×0 GraphicsPlaceholder]

             CreateFcn: ''

       DataTipTemplate: [1×1 matlab.graphics.datatip.DataTipTemplate]

             DeleteFcn: ''

           DisplayName: ''

      HandleVisibility: 'on'

               HitTest: on

         Interruptible: on

              LineJoin: 'round'

             LineStyle: '-'

         LineStyleMode: 'auto'

             LineWidth: 0.5000

                Marker: 'none'

       MarkerEdgeColor: 'auto'

       MarkerFaceColor: 'none'

         MarkerIndices: [1×1000 uint64]

            MarkerMode: 'auto'

            MarkerSize: 6

                Parent: [1×1 Axes]

         PickableParts: 'visible'

              Selected: off

    SelectionHighlight: on

           SeriesIndex: 1

                   Tag: ''

                  Type: 'line'

              UserData: []

               Visible: on

                 XData: [1×1000 double]

             XDataMode: 'manual'

           XDataSource: ''

                 YData: [1×1000 double]

           YDataSource: ''

                 ZData: [1×0 double]

           ZDataSource: ''

图像:

 2.XLim、YLim、FontSize、XTick、XTickLabel、FontName

(1).XLim\YLim

set(gca,'XLim',[0,2*pi]);
%x轴的极限坐标:0-2*pi
set(gca,'YLim',[-1.2,1.2]);
%y轴的极限坐标:-1.2-1.2
%同
%xlim([0,2*pi]);
%ylim([-1.2,1.2]);

 (2).FontSIze字体大小

FontSize字体大小
set(gca,'FontSize',25);

 (3)XTick/XTickLabel

y=sin(x);
plot(x,y);
set(gca,'XLim',[0,2*pi]);
set(gca,'YLim',[-1.2,1.2]);
set(gca,'FontSize',25);
set(gca,'XTick',0:pi/2:2*pi);%0-2pi间隔为pi/2,弧度制
set(gca,'XTickLabel',0:90:360);%用0-360间隔为90的格式取代
%set(gca,’XLim’,[0,4]);设置显示0-4的范围
%set(gca,’XTick’,0:0.5:4);设置显示格式为0-4,步长为0.5

 (4).FontName

set(gca,'FontName','tex');%tex转义字符
set(gca,'XTickLabel',{'0','\pi/2','\pi','3\pi/2','2\pi'});

 三、Line Specification

 

 

Line Specification
>> x= linspace(0,2*pi,1000);
>> y=sin(x);
>> plot(x,y);
>> h=plot(x,y);
>> set(h,'LineStyle','-.','LineWidth',7.0,'Color','g');
%同在绘图时直接改变:
%plot(x,y,’-g’,...
%     ‘LineWidth’,7.0);

delete(h);%删除绘制的曲线h

四、图像中点的设置

1.基本属性

 

 

>> rand(20,1);%随机生成0-1的20*1矩阵
>> set(gca,'FontSize',18);
>> plot(x,'-md','LineWidth',2,'MarkerEdgeColor','k',...
'MarkerFaceColor','g','MarkerSize',10);
%LineWidth:线宽
%MarkerEdgeColor:点的边缘颜色
%MarkerFaceColor:点内部颜色
%MarkerSize:点大小

 2.例题2

hold on
 x=linspace(1,2); y=x.^2; z=sin(2*pi.*x);
plot(x,y,'k','LineWidth',3); plot(x,z,'or','MarkerFaceColor',[0.2,0,1]);
%'MarkerFaceColor',[0.2,0,1] RGB颜色
set(gca,'FontSize',18); xlabel('Time(ms)'); ylabel('f(t)'); title('Mini Assignment #1');
legend({'t^{2}','sin(2\pit)'},'Location','northwest'); 
hold off

 五、绘制多个图像

>> x=-10:0.1:10;
>> y1= x.^2-8;
>> y2= exp(x);
>> figure,plot(x,y1);
>> figure,plot(x,y2);
%gca和gcf指最后绘制图像的属性

 

 六、Position()间距

 七、Subplot()

在一个figure中画很多小figure

>> t=0:0.1:2*pi;
>> x=3*cos(t);
>> y=sin(t);
>> subplot(2,2,1);
>> plot(x,y);axis normal;
>> subplot(2,2,2);plot(x,y);axis square;
>> subplot(2,2,3);plot(x,y);axis equal;
>> subplot(2,2,4);plot(x,y);axis equal tight;

 关于axis:

设置坐标轴范围和纵横比 - MATLAB axis - MathWorks 中国

 八、常用属性

 九、存储

1.saveas

 

 2.Print 高解析度

打印图窗或保存为特定文件格式 - MATLAB print - MathWorks 中国

十、属性编辑器

不需要代码,可直接设置

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值