Matlab 畫圖

MATLAB 操作總結(jié)


如何用命令行保存圖片?

  1. saveas

??用法:saveas( fig, filename, formattype )

??Example:

    x = [2 4 5 6 7];
    bar(x);
    saveas( gcf, 'Barchart.png' )
    saveas( gcf, 'Barchart', 'epsc' ) % save figure as EPS file
  1. print

?? 用法: print( filename, formattype, formatoptions )

??Example:

    % save figure as image file
    bar(1:10)
    print( 'BarPlot', '-dpng' )
    % copy figure to Clipboard
    plot(1:10)
    print( '-clipboard','dmeta' )
    

    fig = figure;
    plot(1:10);
    print( fig, 'MySaveplot', '-dpng' )

畫圖控制

用到的重要函數(shù)有 gca, gcf, set, text
在需要的時(shí)候請(qǐng)仔細(xì)閱讀 MATLAB 中 Axes Properties 等相關(guān)文檔,了解圖形控制中可變參數(shù)。

函數(shù)說明:

  • gca ?返回當(dāng)前坐標(biāo)軸和圖形。

      x = -2*pi:0.1:2*pi;
      y = sin(x);
      plot(x,y)
      xlabel('x')
      ylabel('y')
    
      ax = gca;
      ax.XAxisLocation
      ax.YAxisLocation
      ax.XAxisLocation = 'origin'; % setting x axis location to origin
      ax.YAxisLocation = 'origin'; % setting y axis location to origin
      ax.Box = 'off'; % Turn off the display of the axes outline
      ax.Layer = 'top'; % Make grid lines and tick marks appear over graphics objects
    
mf1.jpg
  • gcf ?返回當(dāng)前圖形的句柄

      surf(peaks)
      fig = gcf;
      fig.Color = [0 0.5 0.5];
      fig.ToolBar = 'none';
    
mf2.jpg
  • set ?設(shè)置圖形目標(biāo)性質(zhì)

    語(yǔ)法: set(H, Name, Value)

      x = 0:30;
      y = [1.5*cos(x); 4*exp(-.1*x).*cos(x); exp(.05*x).*cos(x)]';
      S = stem(x,y);
      NameArray = {'Marker','Tag'};
      ValueArray = {'o','Decaying Exponential';...
      'square','Growing Exponential';...
      '*','Steady State'};
      set(S,NameArray,ValueArray)
    
mf3.jpg

子圖控制

Colorbar控制

Position 參數(shù)為 [left bottom width height]

    x=[60:20:260]; %set x axis ticks
    y=rand(11);  %get something to plot
    h1=subplot(2,1,2); %setup subplot1
    plot(x,y,'-.'); %plot subplot1
    box on  %  leave only x and y axes
    xlim([60 260])  %setup some x axis 
    set(h1,'Xtick',x) %set the x axis ticks to show only x
    h1_pos = get(h1,'Position'); %get the position data for sublot1.
    y2 = 10*y.^2;  %make something up for subplot2
    h2=subplot(2,1,1);  %make subplot2
    plot(x,10*y,'-.'); %plot subplot2
    box on
    set(h2,'Xcolor',[1 1 1]) %make the Y axis line white
    set(h2,'Xtick',[])
    xlim([60 260])  %setup some x axis 
    h2_pos=get(h2,'Position'); 
    set(h2,'Position',[h1_pos(1) h1_pos(2)+h1_pos(4) h2_pos(3:end)]) %using position of subplot1 put subplot2next to it.
mf4.jpg

坐標(biāo)軸控制

  1. 坐標(biāo)軸刻度朝外

    set(gca, 'tickdir', 'out')

  2. 坐標(biāo)軸顏色

    set(gca, 'XColor', 'red')

  3. 其它

     set(gca, 'XLim', [min max]);   % range 
     set(gca, 'XTick', [ markerpoint ]);     % markerpoint
     set(gca, 'XTicklabel', {}];     %marker
     set(gca, 'XGrid', 'on');        %grid on
    

防止圖縮小后字體過小或發(fā)虛

    set(gcf, 'Position', [100 100 260 220]);
    set(gca, 'Position', [.13 .17 .80 .74]);
    figure_Fontsize = 8;
    set(get(gca, 'XLabel'), 'FontSize', figure_Fontsize, 'Vertical', 'top');
    set(get(gca, 'YLabel'), 'FontSize', figure_Fontsize, 'Vertical', 'middle');
    set(findobj('FontSize',10), 'FontSize', figure_Fontsize);
    set(findobj(get(gca, 'Children'), 'LineWidth', 0.5), 'LineWidth', 2);

圖形窗口

colordef 定義繪圖背景色

隨機(jī)數(shù)生成

可用函數(shù): rand, randi, randn, randperm, randsrc, unifrnd

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容