python繪製三維圖
一、初始化
假設已經安裝了matplotlib工具包。
利用matplotlib.figure.Figure建立一個圖框:
1 2 3 4 |
|
二、直線繪製(Line plots)
基本用法:
1 |
|
code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
- 2 , 2 , 100 )
|
三、散點繪製(Scatter plots)
基本用法:
1 |
|
- xs,ys,zs:輸入資料;
- s:scatter點的尺寸
- c:顏色,如c = 'r'就是紅色;
- depthshase:透明化,True為透明,預設為True,False為不透明
- *args等為擴充套件變數,如maker = 'o',則scatter結果為’o‘的形狀
code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
|
四、線框圖(Wireframe plots)
基本用法:
1 |
|
- X,Y,Z:輸入資料
- rstride:行步長
- cstride:列步長
- rcount:行數上限
- ccount:列數上限
code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
五、表面圖(Surface plots)
基本用法:
1 |
|
- X,Y,Z:資料
- rstride、cstride、rcount、ccount:同Wireframe plots定義
- color:表面顏色
- cmap:圖層
code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
|
六、三角表面圖(Tri-Surface plots)
基本用法:
1 |
|
- X,Y,Z:資料
- 其他引數類似surface-plot
code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
|
七、等高線(Contour plots)
基本用法:
1 |
|
code:
1 2 3 4 5 6 7 8 9 10 11 |
|
二維的等高線,同樣可以配合三維表面圖一起繪製:
code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
|
也可以是三維等高線在二維平面的投影:
code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
八、Bar plots(條形圖)
基本用法:
1 |
|
- x,y,zs = z,資料
- zdir:條形圖平面化的方向,具體可以對應程式碼理解。
code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
|
九、子圖繪製(subplot)
A-不同的2-D圖形,分佈在3-D空間,其實就是投影空間不空,對應code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
|
B-子圖Subplot用法
與MATLAB不同的是,如果一個四子圖效果,如:
MATLAB:
1
2
3
subplot(
2
,
2
,
1
)
subplot(
2
,
2
,
2
)
subplot(
2
,
2
,[
3
,
4
])
Python:
1
2
3
subplot(
2
,
2
,
1
)
subplot(
2
,
2
,
2
)
subplot(
2
,
1
,
2
)
code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
|
補充:
文字註釋的基本用法:
code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
|