標籤:

APPs(003)Matlab出圖真的丑嗎?(a)

(默認版本Matlab 2017a以後)

上一次出圖是給工程工作快速做出結果,是從0-1的過程,結果大於過程。寫的簡單粗暴,當然也是可以理解的。(分明就是懶,我要強行洗地)。

這次啰嗦一下plot的論文級別圖片的處理方法:

1,對於Figure類的認識。

一個2D 線圖一般是由祖孫三代完成的

begin{array}{lll} 爺爺 & --- & Figure  爸爸 & --- & Axes 孫子 & --- & Line  end{array}

Figure生了Axes,Axes生了 Line(這就是個比喻,不要怕,不讓你生孩子)

fig = figure();nax = axes(Parent,fig);nln = line(Parent,ax); %此函數默認有XData,YDatanfig.Childrennax.Childrennln.Childrenn

ans = nn Axes with properties:nn XLim: [0 1]n YLim: [0 1]n XScale: linearn YScale: linearn GridLineStyle: -n Position: [1×4 double]n Units: normalizednn Use GET to show all propertiesnnnans = nn Line with properties:nn Color: [0 0 0]n LineStyle: -n LineWidth: 0.500000000000000n Marker: nonen MarkerSize: 6n MarkerFaceColor: nonen XData: [0 1]n YData: [0 1]n ZData: [1×0 double]nn Use GET to show all propertiesnnnans = nn 0×0 empty GraphicsPlaceholder array.n

2,而plot函數是相當於一個直接讓你寫孫子的函數

plt = plot([1:1:2])nplt.Parentnplt.Parent.Parentn

plt = nn Line with properties:nn Color: [0 0.447000000000000 0.741000000000000]n LineStyle: -n LineWidth: 0.500000000000000n Marker: nonen MarkerSize: 6n MarkerFaceColor: nonen XData: [1 2]n YData: [1 2]n ZData: [1×0 double]nn Use GET to show all propertiesnnnans = nn Axes with properties:nn XLim: [1 2]n YLim: [1 2]n XScale: linearn YScale: linearn GridLineStyle: -n Position: [1×4 double]n Units: normalizednn Use GET to show all propertiesnnnans = nn Figure (4) with properties:nn Number: 4n Name: n Color: [0.940000000000000 0.940000000000000 0.940000000000000]n Position: [440 378 560 420]n Units: pixelsnn Use GET to show all propertiesn

3,這就是說,挨個對祖孫三代控制,就能得到很漂亮的圖,

當然最多的人都是想當爸爸的,啊不,都是想控制axes的,

圖的標題,橫坐標,縱坐標,坐標範圍,圖例啥的。

具體各輩份的人能控制什麼參數,請看用matlab自帶幫助文檔,搜索以下關鍵字(可能這些命

令在2014b以後都能用,但是沒有具體查,不保證)

doc Figure Propertiesn doc Axes Propertiesn doc Chart Line Properties % 2017an doc Line Properties % 2017b貌似文檔改叫Line Proppertiesn

4, 放上一個我自己常用的設置函數

function MyDefAx(titleStr,xTitle,yTitle,xLim,yLim)nn% 獲取axnax = gca;nn% 設定字體nax.FontSize = 10;nax.TitleFontWeight = bold;nax.FontName = Times New Roman;nn% 設置大小 8cm*8cm figure//6*6cm axesnax.Parent.Units = centimeters;nax.Parent.Position = [10,10,8,8];nax.Units = centimeters;nax.Position = [1.2,1.2,6,6];nn% 設定box 和 gridnax.Box = on;ngrid on;nax.GridColor = k;nax.GridLineStyle = -;n n% 設定文字n% 也可以設定成 tex 的編譯nax.Title.Interpreter = latex;ntmp = sprintf(textsf{$ %s $},titleStr);nax.Title.String = tmp;nax.Title.Color = k;nax.Title.FontSize = 14;nnax.XLabel.Interpreter = latex;ntmp = sprintf(textsf{$ %s $},xTitle);nax.XLabel.String = tmp;nax.XLabel.Color = k;nax.XLabel.FontSize = 10;nnnax.YLabel.Interpreter = latex;ntmp = sprintf(textsf{$ %s $},yTitle);nax.YLabel.String = tmp;nax.YLabel.Color = k;nax.YLabel.FontSize = 10;nn% 設定範圍nax.XLim = xLim;nax.YLim = yLim; nn% 顯示圖例nlegend(show);nendn

使用案例

plot([1:1:10],2*[1:1:10],ro);nMyDefAx(theta_{alpha}^{beta},x,y,[-2,12],[0,22]) %字元默認使用了Latex 格式n

5,手動改下圖例,

File--->

Export Setup --->

選個合適解析度,或者乾脆選個Vector的輸出--->

eps/tif/jpg/svg/png

隨你雜誌要求了


推薦閱讀:

加速你的MATLAB開發(2): 使用Version Control
matlab畫圖,明明標記了11個點的坐標,最後畫出來的圖卻只有10個點,坐標沒有重疊。這是為什麼?
matlab把數值數組轉成分立的字元組成的元胞數組?
機器學習筆記16 —— 編程作業5線性回歸演算法的評估
Deep Learning with MATLAB(懶人版)

TAG:MATLAB |