標籤:style blog http color 2014 cti
一幅圖是由許多元素組成的。包括表徵圖題,x軸標籤,y軸標籤,刻度標記等。圖1給出了各個元素的一個。
這些所有的元素在scilab中都是可以用代碼控制的。
標題
上個筆記上介紹了用xtitle()函數可以在圖上添加標題。比如:
title("My Plot");
實際上,title函數有三種形式:
title(my_title)
title(my_title,<Property>)
title(<axes_handle>,<my_title>,<Property>)
上次只是用的最簡單的形式,利用第二種形式就可以設定標題的字型、字型大小等屬性了。下面給個例子:
x = 0:0.1:10;plot(x, sin);title("$f=sin(x)$","fontname","helvetica bold", "fontsize", 4, "color", "red");
上面例子中,"$f=sin(x)$" 是 Latex 程式碼片段,scilab 支援基本的latex 數學模式,因此可以產生漂亮的標題。
後面設定了字型為helvetica bold, 字型大小大小為4,顏色為紅色。除此之外還可以設定其他的參數,具體可以參閱協助文檔。
X 軸的Label 和y軸的Label 有兩個獨立的函數來設定。這兩個函數的用法與 title 函數基本相同,下面舉個例子:
x = linspace(-5,5,51);y = 1 ./(1+x.^2);plot(x,y,'o-b');xlabel("$-5\le x\le 5$","fontsize",4,"color","red");ylabel("$y(x)=\frac{1}{1+x^2}$","fontsize",4,"color","red");title("Runge function (#Points ="+string(length(x))+").","color","red","fontsize",4);
另外,無論是標題還是Label,都可以是多行的,對上面的例子稍作修改。
xlabel(["$-5\le x\le 5$";"Second Line"],"fontsize",4,"color","red");ylabel(["$y(x)=\frac{1}{1+x^2}$";"Second Line"],"fontsize",4,"color","red");title(["Runge function (#Points ="+string(length(x))+").";"Second Line"],"color","red","fontsize",4);
如果有多條曲線,就需要有個legend 來說明哪條曲線是什麼。見下面的例子:
x = linspace(-5.5,5.5,51);y = 1 ./(1+x.^2);plot(x,y,'ro-');plot(x,y.^2,'bs:');xlabel(["x axis";"(independent variable)"],"fontsize", 4);ylabel("y axis","fontsize", 4);title("Functions","fontsize", 4);legend(["Functions #1";"Functions #2"])
Legend 的字型和字型大小不能像label 那樣設定。實驗後發現,legend 和刻度上的字共用一套控制命令:
xset("font size", 4);