假设我有3个关于纬度、经度和时间表的信息的数据框,这样每个列代表一个不同的对象,并且每一行代表一个时间点。
latitudes =
object 1 2 3
0 -8.064267 -8.047483 -8.056339
1 -8.064267 -8.047483 -8.056339
2 -8.064267 -8.047483 -8.056339
3 -8.064267 -8.047483 -8.056339
4 -8.064267 -8.047483 -8.056339
5 -8.064267 -8.047483 -8.056339
longitudes =
object 1 2 3
0 -34.878386 -34.904086 -34.889661
1 -34.878386 -34.904086 -34.889661
2 -34.878386 -34.904086 -34.889661
3 -34.878386 -34.904086 -34.889661
4 -34.878386 -34.904086 -34.889661
5 -34.878386 -34.904086 -34.889661
times =
object 1 2 3
0 2016-03-05 07:52:00 2016-03-05 16:26:00 2016-03-05 16:58:00
1 2016-03-05 08:19:00 2016-03-05 16:42:00 2016-03-05 17:45:00
2 2016-03-05 08:52:00 2016-03-05 17:06:00 2016-03-05 17:58:00
3 2016-03-05 09:36:00 2016-03-05 18:21:00 2016-03-05 18:23:00
4 NaT 2016-03-05 23:06:00 2016-03-05 22:38:00
5 NaT 2016-03-05 23:09:00 NaT
我想绘制一个3D轨迹,在Z轴上的时间,X轴上的经度,Y轴上的纬度,其中所有物体的轨迹都在同一个情节上。我该怎么做?
这是我的尝试,但不起作用:
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111,projection='3d')
ax.plot(longitudes.values,latitudes.values,times.values)
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('Time')
plt.show()
错误:
ValueError: third arg must be a format string
谢谢你
最佳答案
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('Time')
for t in times.columns:
ax.plot(longitudes[t].values, latitudes[t].values, times[t].values, label='t')
ax.legend()
lm.png