You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Plotly Python动画报错:PlotlyRequestError: Figure字段无效求助

问题:Plotly单站点温度时间序列动画制作报错求助

我正在尝试用Plotly制作时间序列数据的动画,已经用相同数据成功生成了非动画图表。最终目标是实现点的颜色随对应时间的温度变化而改变的动画,为了简化流程,先从单站点的温度变化动画开始尝试。

数据样例

weather.head()
temp_f    lat         long        timestamp
66.9      45.683189   -111.028275 2018-05-04 13:21:00
66.8      45.683189   -111.028275 2018-05-04 13:33:00
66.7      45.683189   -111.028275 2018-05-04 13:52:00
68.5      45.683189   -111.028275 2018-05-04 14:06:00
68.5      45.683189   -111.028275 2018-05-04 14:08:00

编写的代码

temps = list(weather.temp_f)
columns = []
for i in range(0, len(temps)):
    new_column = Column(temps[i], 'temp{}'.format(i))
    columns.append(new_column)
grid = Grid(columns)

#Layout dictionary
layout = go.Layout(
    autosize = True,
    hovermode = 'closest',
    #The mapbox dictionary gives a bunch of parameters to the Mapbox API
    mapbox = dict(
        #Omitted for brevity
    ),
)

#Data dictionary
data = [
    go.Scattermapbox(
        #Since my data are all collected from the same weather station, there is only one point on the scatter
        #I plan to scale this up to an arbitrary number of stations
        lat = weather.lat,
        lon = weather.long,
        #Makes it a scatter plot
        mode = 'markers',
        #Sets parameters for the appearance of the markers
        marker = dict(
            size = 8,
            #The marker color is matched to the temperature for that observation
            color = grid.get_column_reference('temp0'),
            colorscale = [
                [0,"rgb(5, 10, 172)"],[0.35,"rgb(40, 60, 190)"],
                [0.5,"rgb(70, 100, 245)"],[0.6,"rgb(90, 120, 245)"],
                [0.7,"rgb(106, 137, 247)"],[1,"rgb(220, 220, 220)"]
            ]
        ),
        text=['Station xyz'],
    )
]

#Frames dictionary, this is most likely where the problem is!! I was mainly following the filled area animation for this part.
frames = [{'data': [{'marker':[
    #I want the color of the point to change based on the temperature for that observation
    {'color': grid.get_column_reference('temp{}'.format(k))}
]}
]} for k in range(0, len(temps))]

#Generate the figure using the above parameters
fig = dict(data=data, layout=layout, frames=frames)
py.icreate_animations(fig, filename='Station xyz')

报错信息

PlotlyRequestError: Figure field is invalid. Reason: Raw data arrays are not allowed at this endpoint. Use grid references instead. Raw data found at the following paths in the figure [('data', 0, u'lat'), ('data', 0, u'lon'), ('data', 0, u'text')]

恳请各位帮忙解决这个问题。


内容的提问来源于stack exchange,提问作者Peter

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 07:08:21