Matlab绘图

1. Matlab初阶绘图

函数参数示例
plot(x,y),plot(y)向量对,不写x默认1:length(y)
legend(‘y1’, ‘y2’, ‘y3’)函数名字符串图例,和plot的几个向量对 对应
title(), x/y/zlabel()标题、坐标轴名字符串标题,
text()基于latex做数学公式的text
annotation()画箭头

一些控制

grid on/off
box on/off
axis on/off
axis normal/square/equal/equal tight…对当前图的操作
hold on/off

plot的风格

doc LineSpec

plot(x, y, 'str') % str定义不同风格
  1. 图表

    一个图表含有的object

    ​ 图表、坐标轴、线、文本…

    取得这些object

    1. 坐标轴相关
    x = linspace(0, 2*pi, 1000)
    y = sin(x)
    h = plot(x,y) % line的handle为h,axes和figure默认的handle分别为gca,gcf
    get(h) % 获取line的属性
    
    set(h) % 设置line的属性
    set(gca, 'XLim', []) % 设置axis的范围
    set(gca, 'YLim', []) % 设置ayis的范围
    % 可替代的方式
    xlim([ ])
    ylin([ ])
    
    set(gca, 'FontSize', 25) % 设置字体大小
    
    1. 线相关

      set(h, 'LineStyle', '-.', 'LineWidth', 7.0, 'Color', 'g')
      % 可替代的方式
      plot(x,y, '-.g', 'LineWidth', 7.0)
      
    2. Marker,标记点

      face & edge 的颜色

      plot(x,'-md','LineWidth', 2, 'MarkerEdgeColor','k', 'MarkerFaceColor', 'g', 'MarkerSize', 10)
      
    3. 图表相关

      % 多个plot,多个figure
      figure('Position', [left, bottom, width, height])% 当存在多图表时候,谨慎使用gcf,gcf表示现在的图表
      
      % 1个figure,多个plot
      subplot(m, n, 1) %m行,n列, 第一个1位置
      plot(x,y)
      axis normal/square/equal/equal tight % 4种坐标轴形状
      
      subplot(m, n, 2) % 第2个位置
      
    4. 保存图片

      saveas(gcf, '<filename>', '<formattype>')
      
      formattype
      jpeg
      png
      tiff
      pdf
      eps
      meta
  2. Matlab进阶绘图

    特殊的plots

    logspace(start, end, num)
    loglog加上网格,便于观察
    semilogxset(gca, ‘XGid’, ‘on’)
    semilogy
    plotyy(x,y1, x, y2)2条y轴
    统计图表
    hist(y, num of bins)柱状图,整体,统计图表
    bar(x) bar(matrix) bar3(matrix) bar(y, ‘stacked’) barh(y)柱状图,当为矩阵时候,根据行分为rows组(二维左右,三维并排),添加stacked是将每组数据堆放
    pie(x, [0,0,0,1]) pie3饼图,[ ]里按x小到大的顺序,为1则扇形分开
    polar极坐标
    stairs楼梯
    stem柱子
    boxplot
[AX,H1,H2] = plotyy(x, y1,x, y2) % 获取axes,line1,line2的handle
set(get(AX(1),'Ylabel'), 'String', 'Left Y-axis')
set(get(AX(2),'Ylabel'), 'String', 'Left Y-axis')
set(H1, 'LineStype', '--')
set(H2, 'linestyle', ':')
画图
fill()
配色P6-33:00
imagesc()用颜色代表第三个维度
colorbar
colormap()色系
3D 画图
plot3(x,y,z)
surf基本曲面(第三维是若干个平面)
meshgird(x,y)
surfc
surface基本曲面(第三维是若干个平面)
mesh网格曲面
meshc曲面+等高线
contour等高线
contourf
view()
light()
patch()
[X,Y] = meshgrid(x,y)
Z = X.exp(-X.^2-Y.^2)
mesh(X,Y,Z)
surf(X,Y,Z)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值