Scilab 的繪圖函數(2)

來源:互聯網
上載者:User

標籤: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); 



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.