【问题标题】:Heatmap error "TraitError: The 'locations' trait of a Heatmap instance must be of length"热图错误“TraitError:热图实例的'位置'特征必须是长度”
【发布时间】:2021-12-28 19:41:29
【问题描述】:

我正在尝试在 Jupyter Notebook 上使用 Javascript 运行将坐标注册到热图上的代码。我的代码是:

import gmaps
import gmaps.datasets
gmaps.configure(api_key="MY API KEY")

data = [(-89.91161093276477, 35.241969778429194), (-89.87947624903887, 35.195319161704404), (-89.81418532101328, 35.17188216058175), (-89.75643652692003, 35.183538628834484), (-89.7496498284386, 35.14509890887518), (-89.78504762327763, 35.063349559432304), (-89.83100682136623, 35.013757847903044), (-89.85342496546569, 35.001086997562474)]
m = gmaps.Map()
heatmap_layer = gmaps.Heatmap(data=data)
m.add_layer(heatmap_layer)
m

但我不断收到错误:

TraitError: The 'locations' trait of a Heatmap instance must be of length 1 <= L <= 9223372036854775807, but a value of [] was specified.

这是什么意思,我该如何解决?

【问题讨论】:

    标签: python google-maps jupyter-notebook


    【解决方案1】:

    您看到此错误是因为该函数需要 locations 并且您没有在那里定义任何内容。我认为您也没有正确调用您的heatmap_layer

    https://jupyter-gmaps.readthedocs.io/en/latest/tutorial.html#heatmaps

    试试这个:

    import gmaps.datasets
    gmaps.configure(api_key="MY API KEY")
    
    locations = [(-89.91161093276477, 35.241969778429194), (-89.87947624903887, 35.195319161704404), (-89.81418532101328, 35.17188216058175), (-89.75643652692003, 35.183538628834484), (-89.7496498284386, 35.14509890887518), (-89.78504762327763, 35.063349559432304), (-89.83100682136623, 35.013757847903044), (-89.85342496546569, 35.001086997562474)]
    m = gmaps.Map()
    heatmap_layer = gmaps.heatmap_layer(locations)
    m.add_layer(heatmap_layer)
    m
    

    【讨论】:

      猜你喜欢
      • 2019-01-08
      • 1970-01-01
      • 2016-01-22
      • 2015-07-26
      • 1970-01-01
      • 1970-01-01
      • 2013-06-28
      • 1970-01-01
      • 2018-10-10
      相关资源
      最近更新 更多