直接上代码,这个比较简单,没什么注释。之前是直接连接MySQL的代码,但是和这个差别也就是导入数据方法不一样,写好端口号和地址就可以,很简单,这里就不放了。
import pandas as pd
import matplotlib as mpl
from mpl_toolkits.mplot3d import Axes3Dimport numpy as np
import matplotlib.pyplot as plt
data = pd.read_csv("Result2.0.csv")
print(data)
a="XXX"
UnitLongitude = data['UnitLongitude'][data['UnitName'] == a] #取UnitLongitude列的数据,且满足UnitName列值为a的数据
print(UnitLongitude)
UnitLatitude = data['UnitLatitude'][data['UnitName'] == a]
print(UnitLatitude)
UnitAltitude = data['UnitAltitude_m'][data['UnitName'] == a]
print(UnitAltitude)
#绘图
mpl.rcParams['legend.fontsize'] = 10
fig =plt.figure)
ax= fig.gca(projection='3d')
y = UnitLongitude
x = UnitLatitude
z =UnitAltitude
ax.set_xlabel('Latitude')
ax.set_ylabel('Longitude')
ax.set_zlabel('Altitude')
ax1 = fig.gca(projection='3d')
ax1.plot(x,y,label='Ground slide track projection') #绘制地面投影轨迹
ax.plot(x,y,z,'g-',label='Air flight 3D trajectory')
ax.legend()
plt.show()