# 使用matplotlib对EC数据进行可视化探索

import matplotlib.pyplot as plt
import numpy as np

def height():
f = open('ecpl_2018021500000_H_0200.txt', 'r')
z = []
for line in xfile:
z.append(line)
xsplit = []
for item in z:
xsplit.append(item.split())

ndz = np.array(xsplit[::-1])

return ndz

def contour():
plt.figure()
plt.title('ecpl 201802150000 200hpheight')
plt.xlabel('longtitude(degree)')
plt.ylabel('latitude(degree)')

#nlon, nlat = coordinate()
x = np.linspace(60, 150, 361)
y = np.linspace(-10, 60, 281)
X, Y = np.meshgrid(x, y)
plt.contourf(X, Y, height(), 10, alpha=0.9, cmap=plt.get_cmap('winter'))
Con = plt.contour(X, Y, height(), 10, colors='black')
plt.clabel(Con, inline=True, fontsize=7)
plt.show()

if __name__ == '__main__':
contour()


plt.contourf用于创建等高线图底图，'10'表示等高线层数，alpha表示图像透明度，cmap用于控制配色方案

#matpoltlib库自带配色方案见matpoltlib-colormap

plt.contour和plt.clabel用于创建等高线和标线字，color定义等高线颜色，inline表示数字位于等高线内，fontsize控制字体大小。

3D图制作:

3D图制作需要Axes3D库，直接安装mpl_toolkits即可

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np

def height():
f = open('ecpl_2018021500000_H_0200.txt', 'r')
z = []
for line in xfile:
z.append(line)
xsplit = []
for item in z:
xsplit.append(item.split())

nxsplit = []
for lst in xsplit:
nlst = []
for item in lst:
nitem = float(item)
nlst.append(nitem)
nxsplit.append(nlst)

ndarray = np.array(nxsplit[::-1])

return ndarray

def tdaxes():
fig = plt.figure()
ax = Axes3D(fig)
plt.title('ecpl 201802150000 200hpheight')
plt.xlabel('longtitude(degree)')
plt.ylabel('latitude(degree)')

lon = np.linspace(60, 150, 361)
lat = np.linspace(-10, 60, 281)
Lon, Lat = np.meshgrid(lon, lat)
H = height()

#Z = np.array((Lon + Lat) / 2)
#print(type(H), type(Z))
#print(type(Z[0][0]), type(Lon[0][0]))

ax.plot_surface(Lon, Lat, H, rstride=1, cstride=1, cmap=plt.cm.coolwarm)

plt.show()

if __name__ == '__main__':
tdaxes()

• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120