Scilab 的畫圖函數(3)
阿新 • • 發佈:2017-08-04
str ont 語句 pop 原來 調整 ng- label tle
),縱坐標為對數(log).
我們在做數據畫圖或函數圖像時常常須要使用對數坐標系。尤其是數據的範圍跨越非常多個數量級時。通常的線性坐標系下無法表現出數據特征。
Scilab 中Plot函數無法畫出對數坐標。須要使用 plot2d 函數。
plot2d 函數的基本使用方法例如以下:
plot2d([logflag,][x,],y[,style[,strf[,leg[,rect[,nax]]]]])
plot2d([logflag,][x,],y,<opt_args>)
以下是一個簡單的樣例:
iter = linspace(0,10,11); err = 10.^(-iter); plot2d("nl", iter, err, style=2); set(gca(),"grid",[1 1]);
這個樣例假設在普通的坐標系下看,是這個樣子的:
plot(iter,err); set(gca(),"grid",[1 1]);
因為數據非常快就非常接近0了。在圖中非常難看出後面的趨勢。
以下來具體的解說一下plot2d函數。
plot2d("nl", iter, err, style=2);
“nl” 表示,橫坐標為正常的模式(normal
Style = 2 表示的是曲線的顏色。2 表示的是colormap 中的第二項,也就是藍色。
假設是負數。則表示用不同的線型。假設既要設置曲線的顏色,又要設置線型,那麽。
。。臨時還沒搞定。
以下再給一個樣例,通過rect參數控制xy的範圍:
x=[0:0.1:2*%pi]'; plot2d(x,[sin(x) sin(2*x) sin(3*x)],rect=[0,0,6,0.5]);
有點跑題了,接著介紹對數坐標系畫圖。
以下再給一個樣例:
ind = linspace(0,6,7); iter = 10.^ind; err1 = 10.^(-ind); err2 = (10.^(-ind)).^2; xset("font size", 4); plot2d("ll", iter, err1, style=2); plot2d("ll", iter, err2, style=3); title("Loglog","fontsize", 4); xlabel("Iterations","fontsize", 4); ylabel("Error","fontsize", 4); set(gca(),"grid",[5 5]); legend(['error1';'error2'],"in_lower_left");
這個圖是雙對數坐標,同一時候還調整了圖上的文字。須要註意的是:
xset("font size", 4);
語句一定要在
legend([‘error1‘;‘error2‘],"in_lower_left");
語句之前調用。否則得到的圖形的legend 的字號會有問題,以下是個實驗,先運行例如以下語句:ind = linspace(0,6,7); iter = 10.^ind; err1 = 10.^(-ind); err2 = (10.^(-ind)).^2; plot2d("ll", iter, err1, style=2); plot2d("ll", iter, err2, style=3); title("Loglog","fontsize", 4); xlabel("Iterations","fontsize", 4); ylabel("Error","fontsize", 4); set(gca(),"grid",[5 5]); legend(['error1';'error2'],"in_lower_left");
這個圖形是和我們的預期一樣的。標題和Label的字號變大了,刻度和Legend的字號還是原來的大小。
接著運行:
xset("font size", 4);
結果是刻度上的字號更新為正確的大小了,可legend 的字號沒變。看來這個是 scilab 的一個bug。
所以我們須要先設置字號。然後調用legend 函數。Scilab 的畫圖函數(3)