【问题标题】:How to go from lat/long data to surface plot如何从纬度/经度数据到曲面图
【发布时间】:2019-07-24 08:43:46
【问题描述】:

从纬度/经度数据创建曲面图,Z 轴是某个纬度/经度位置出现的次数

我曾尝试使用 pandas 创建数据透视表,但似乎无法正常工作。它们的绘图不正确。

df2 = pd.pivot_table(df, index=['latitude', 'longitude'], 
aggfunc='count')

fig = plt.figure(figsize = (18, 18))
ax = Axes3D(fig)

x = (df2['latitude'])
y = (df2['longitude'])
z = (df2['count'])

surf = ax.plot_trisurf(x, y, z, cmap=cm.jet, linewidth=0.1)
fig.colorbar(surf, aspect = 5)
plt.show()

这是数据透视表,通常我的数据只是(纬度,经度)。在支点中,我计算了某个纬度/经度位置的命中次数。我认为问题在于枢轴的索引,您可以看到“计数”高出一行。

                count
latitude longitude  
20.1    1.1        3
20.2    1.2        3
        1.3        6
20.3    1.2        5
        1.5        5
20.4    1.1        6
        1.2        6
20.5    1.3        3
        1.4        1
        1.6        4

【问题讨论】:

  • 剧情有什么问题?看起来您还缺少一些纬度条目
  • 纬度条目没有丢失。一个纬度可以有多个经度组合(反之亦然)。然后我计算了这个特定纬度/经度在我的数据集中存在的次数。

标签: python pandas numpy dataframe pivot


【解决方案1】:

我通过使用以下代码展平表格来修复它:df2_flattened = pd.DataFrame(df2.to_records())。现在绘图成功了,因为纬度、经度和计数都填得很好。

【讨论】:

    猜你喜欢
    • 2010-09-05
    • 1970-01-01
    • 2016-02-04
    • 1970-01-01
    • 1970-01-01
    • 2019-10-27
    • 1970-01-01
    • 1970-01-01
    • 2013-09-09
    相关资源
    最近更新 更多