import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
mpl.rcParams['legend.fontsize'] = 20 # mpl模塊載入的時候加載配置信息存儲在rcParams變量中,rc_Params_from_file()函數從文件加載配置信息
font = {
'color' : 'b',
'style' : 'oblique',
'size' : 20,
'weight' : 'bold'
}
fig = plt.figure(figsize=(16,12)) # 參數爲圖片大小
ax = fig.gca(projection='3d') #get current axes,且座標軸是3d的
#準備數據
theta = np.linspace(-8 * np. pi, 8 * np.pi, 100) #生成等差數列,[-8π,8π],個數爲100
z = np.linspace(-2, 2, 100) #[-2,2]容量爲100的等差數列,此處數量必須與theta保持一致,因爲下面要做對應元素的運算
r = z ** 2 + 1 # **代表乘方, 2**3就是2的3次方
x = r * np.sin(theta) # [-5,5]
y = r * np.cos(theta) # [-5,5]
ax.set_xlabel("X", fontdict=font)
ax.set_ylabel("Y", fontdict=font)
ax.set_zlabel("Z", fontdict=font)
ax.set_title("Line Plot", alpha=0.5, fontdict=font) # 設置標題; alpha 參數指透明度 transparent
ax.plot(x, y, z, label='parametric curve') # label 圖例
ax.legend(loc='upper right') #legend(圖例)的位置可選: upper right/left/center, lower right/left/center, best 等等
plt.show()
Python3D繪圖工具Axes3D -lineplot
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.