# Chapter 3 二維繪圖的進階功能

(1)

. . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . .

. .

. . . . .

## Spring 2020

Hung-Yuan Fan (范洪源), Dep. of Math., NTNU, Taiwan Chap. 3, Computer Programming 1/76

(2)

(3)

. . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . .

. .

. . . . .

## 二維繪圖額外的繪圖功能

Hung-Yuan Fan (范洪源), Dep. of Math., NTNU, Taiwan Chap. 3, Computer Programming 3/76

(4)

1

2

(5)

. . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . .

. .

. . . . .

1

2

## semilogx、semilogy 和 loglog 函式的語法說明如下:

Hung-Yuan Fan (范洪源), Dep. of Math., NTNU, Taiwan Chap. 3, Computer Programming 4/76

(6)

(7)

. . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . .

. .

. . . . .

## semilogx(x,sin(x) ./ (x+1));

Hung-Yuan Fan (范洪源), Dep. of Math., NTNU, Taiwan Chap. 3, Computer Programming 5/76

(8)

(9)

. . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . .

. .

. . . . .

## semilogy(x,y);

Hung-Yuan Fan (范洪源), Dep. of Math., NTNU, Taiwan Chap. 3, Computer Programming 6/76

(10)

1

2

(11)

. . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . .

. .

. . . . .

1

2

## logspace: 在陣列點之間建立對數的間隔。

### n 是所要產生陣列的點數。

Hung-Yuan Fan (范洪源), Dep. of Math., NTNU, Taiwan Chap. 3, Computer Programming 7/76

(12)

(13)

. . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . .

. .

. . . . .

## 1.0000 1.2915 1.6681 2.1544 2.7826 3.5938 4.6416 5.9948 7.7426 10.0000

Hung-Yuan Fan (范洪源), Dep. of Math., NTNU, Taiwan Chap. 3, Computer Programming 8/76

(14)
(15)

. . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . .

. .

. . . . .

## plotyy(x,sqrt(x)+sin(6*x),x,exp(x));

Hung-Yuan Fan (范洪源), Dep. of Math., NTNU, Taiwan Chap. 3, Computer Programming 10/76

(16)

## plotyy(x,sqrt(x)+sin(6*x),x,exp(x));

(17)

. . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . .

. .

. . . . .

### Figure: 函式 plot(左) 和 plotyy(右) 的繪圖結果

Hung-Yuan Fan (范洪源), Dep. of Math., NTNU, Taiwan Chap. 3, Computer Programming 11/76

(18)

(19)

. . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . .

. .

. . . . .

## % 只觀察在 0 ≤ x ≤ 6 和 −0.6 ≤ y ≤ 0.6 範圍內的函數圖形

Hung-Yuan Fan (范洪源), Dep. of Math., NTNU, Taiwan Chap. 3, Computer Programming 13/76

(20)

(21)

. . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . .

. .

. . . . .

## 使用 hold off 指令，可以切換圖形視窗回到預設的狀態。

Hung-Yuan Fan (范洪源), Dep. of Math., NTNU, Taiwan Chap. 3, Computer Programming 15/76

(22)

(23)

. . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . .

. .

. . . . .

## hold off;

Hung-Yuan Fan (范洪源), Dep. of Math., NTNU, Taiwan Chap. 3, Computer Programming 16/76

(24)

(25)

. . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . .

. .

. . . . .

### 產生多個圖形視窗

Hung-Yuan Fan (范洪源), Dep. of Math., NTNU, Taiwan Chap. 3, Computer Programming 18/76

(26)

## .. .

(27)

. . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . .

. .

. . . . .

### 子圖形

Hung-Yuan Fan (范洪源), Dep. of Math., NTNU, Taiwan Chap. 3, Computer Programming 20/76

(28)

(29)

. . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . .

. .

. . . . .

## >> subplot(2,2,1); plot(x,sin(x));

Hung-Yuan Fan (范洪源), Dep. of Math., NTNU, Taiwan Chap. 3, Computer Programming 21/76

(30)

(31)

. . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . .

. .

. . . . .

## >> grid on;

Hung-Yuan Fan (范洪源), Dep. of Math., NTNU, Taiwan Chap. 3, Computer Programming 22/76

(32)

(33)

. . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . .

. .

. . . . .

## >>hold off;

Hung-Yuan Fan (范洪源), Dep. of Math., NTNU, Taiwan Chap. 3, Computer Programming 23/76

(34)

(35)

. . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . .

. .

. . . . .

## >> subplot(2,2,4); plot(x,floor(x));

Hung-Yuan Fan (范洪源), Dep. of Math., NTNU, Taiwan Chap. 3, Computer Programming 24/76

(36)

(37)

. . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . .

. .

. . . . .

## plot(x,y,'-ko','LineWidth',3.0,'MarkerSize',6,...

### 'MarkerEdgeColor','r','MarkerFaceColor','g')

Hung-Yuan Fan (范洪源), Dep. of Math., NTNU, Taiwan Chap. 3, Computer Programming 26/76

(38)

(39)

. . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . .

. .

. . . . .

## ^{xxx}: 上標符號，例如: x^{3} 會顯示為 x3 。

Hung-Yuan Fan (范洪源), Dep. of Math., NTNU, Taiwan Chap. 3, Computer Programming 28/76

(40)

(41)

. . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . .

. .

. . . . .

## ylabel(' \it{y(t)} ') ; grid on;

Hung-Yuan Fan (范洪源), Dep. of Math., NTNU, Taiwan Chap. 3, Computer Programming 30/76

(42)

(43)

. . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . .

. .

. . . . .

## Lecture 2極座標圖

Hung-Yuan Fan (范洪源), Dep. of Math., NTNU, Taiwan Chap. 3, Computer Programming 32/76

(44)

(45)

. . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . .

. .

. . . . .

## title('Plot of r = 1 - cos \theta');

Hung-Yuan Fan (范洪源), Dep. of Math., NTNU, Taiwan Chap. 3, Computer Programming 34/76

(46)

(47)

. . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . .

. .

. . . . .

### 函式 fplot 的語法

Hung-Yuan Fan (范洪源), Dep. of Math., NTNU, Taiwan Chap. 3, Computer Programming 36/76

(48)

(49)

. . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . .

. .

. . . . .

## >> fplot('x - cos(x^3)',[-3,3],'ro-.')

Hung-Yuan Fan (范洪源), Dep. of Math., NTNU, Taiwan Chap. 3, Computer Programming 37/76

(50)

(51)

. . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . .

. .

. . . . .

## >> ezplot(’sin(1/x)’,[-pi, pi])

Hung-Yuan Fan (范洪源), Dep. of Math., NTNU, Taiwan Chap. 3, Computer Programming 39/76

(52)

(53)

. . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . .

. .

. . . . .

## >> ezplot(’x^3+4*x^2-3*x+1-y^2’)

Hung-Yuan Fan (范洪源), Dep. of Math., NTNU, Taiwan Chap. 3, Computer Programming 40/76

(54)

(55)

. . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . .

. .

. . . . .

## >> ezplot(’3*cos(t)’,’4*sin(t)’,[0,3*pi/2])

Hung-Yuan Fan (范洪源), Dep. of Math., NTNU, Taiwan Chap. 3, Computer Programming 41/76

(56)

(57)

. . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . .

. .

. . . . .

## % 心臟線將慢慢呈現在您眼前!

Hung-Yuan Fan (范洪源), Dep. of Math., NTNU, Taiwan Chap. 3, Computer Programming 43/76

(58)

(59)

. . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . .

. .

. . . . .

## % 請試試看，見證奇蹟的時刻即將開始!

Hung-Yuan Fan (范洪源), Dep. of Math., NTNU, Taiwan Chap. 3, Computer Programming 44/76

(60)

(61)

. . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . .

. .

. . . . .

## Recall: 設定圖形標題和座標軸的解說文字，可使用下列函式:

Hung-Yuan Fan (范洪源), Dep. of Math., NTNU, Taiwan Chap. 3, Computer Programming 46/76

(62)

(63)

. . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . .

. .

. . . . .

## text(5.5, 3, 'x*cos(x)');

Hung-Yuan Fan (范洪源), Dep. of Math., NTNU, Taiwan Chap. 3, Computer Programming 48/76

(64)

(65)

. . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . .

. .

. . . . .

## 額外的二維圖形類別

Hung-Yuan Fan (范洪源), Dep. of Math., NTNU, Taiwan Chap. 3, Computer Programming 50/76

(66)

## 羅盤圖 (compass plots)

(67)

. . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . .

. .

. . . . .

### 統計繪圖函式的語法

Hung-Yuan Fan (范洪源), Dep. of Math., NTNU, Taiwan Chap. 3, Computer Programming 52/76

(68)

## axis([0 7 0 10]);

(69)

. . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . .

. .

. . . . .

### 範例的圖結果 (承上頁)

Hung-Yuan Fan (范洪源), Dep. of Math., NTNU, Taiwan Chap. 3, Computer Programming 54/76

(70)

## axis([0 7 0 10]);

(71)

. . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . .

. .

. . . . .

### 範例的繪圖結果 (承上頁)

Hung-Yuan Fan (范洪源), Dep. of Math., NTNU, Taiwan Chap. 3, Computer Programming 56/76

(72)

## ylabel(' \bf \it x');

(73)

. . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . .

. .

. . . . .

### 範例的繪圖結果 (承上頁)

Hung-Yuan Fan (范洪源), Dep. of Math., NTNU, Taiwan Chap. 3, Computer Programming 58/76

(74)

## legend('One','Two','Three','Four','Five');

(75)

. . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . .

. .

. . . . .

### 範例的繪圖結果 (承上頁)

Hung-Yuan Fan (范洪源), Dep. of Math., NTNU, Taiwan Chap. 3, Computer Programming 60/76

(76)

## legend('One','Two','Three','Four','Five');

(77)

. . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . .

. .

. . . . .

### 範例的繪圖結果 (承上頁)

Hung-Yuan Fan (范洪源), Dep. of Math., NTNU, Taiwan Chap. 3, Computer Programming 62/76

(78)

(79)

. . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . .

. .

. . . . .

## 1 2 3 2 1 0 1 2 0 1

Hung-Yuan Fan (范洪源), Dep. of Math., NTNU, Taiwan Chap. 3, Computer Programming 64/76

(80)

(81)

. . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . .

. .

. . . . .

## >> hist(data2,20)

Hung-Yuan Fan (范洪源), Dep. of Math., NTNU, Taiwan Chap. 3, Computer Programming 65/76

(82)

(83)

. . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . .

. .

. . . . .

## axis([0 7 0 10]);

Hung-Yuan Fan (范洪源), Dep. of Math., NTNU, Taiwan Chap. 3, Computer Programming 66/76

(84)

(85)

. . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . .

. .

. . . . .

## 仍是以直角坐標 (x, y) 作為繪圖資料點，並將原點與資料點之間的連線段以箭號表示。

Hung-Yuan Fan (范洪源), Dep. of Math., NTNU, Taiwan Chap. 3, Computer Programming 68/76

(86)

(87)

. . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . .

. .

. . . . .

## 利用 plot 函式對二維陣列繪圖

Hung-Yuan Fan (范洪源), Dep. of Math., NTNU, Taiwan Chap. 3, Computer Programming 70/76

(88)

(89)

. . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . .

. .

. . . . .

## ylabel(' \bf \it y');

Hung-Yuan Fan (范洪源), Dep. of Math., NTNU, Taiwan Chap. 3, Computer Programming 72/76

(90)

(91)

. . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . .

. .

. . . . .

## ylabel(' \bf \it y');

Hung-Yuan Fan (范洪源), Dep. of Math., NTNU, Taiwan Chap. 3, Computer Programming 74/76

(92)

(93)

. . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . .

. .

. . . . .

## Thank you for your attention!

Hung-Yuan Fan (范洪源), Dep. of Math., NTNU, Taiwan Chap. 3, Computer Programming 76/76

Updating...

## References

Related subjects :