Plotly动画Python,PlotlyRequestError:图字段无效

时间:2018-05-19 20:45:43

标签: python plotly

我正在尝试使用plotly来设置时间序列数据的动画。我使用相同的数据成功制作了非动画情节:https://plot.ly/~peterasmuth/4。最终,我想要做的是创建一个动画,其中每个点的颜色根据给定时间的温度而变化。为了简化过程,我尝试在一个点上设置温度变化的动画。

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

没有一个阴谋动画教程涵盖了如何完全做到这一点,但我尽力调整我能找到的(按我使用它们的数量排序):https://plot.ly/python/animations/https://plot.ly/python/filled-area-animation/https://plot.ly/python/heatmap-animation/https://plot.ly/python/gapminder-example/

这是我的尝试:

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')]

有人可以帮我解决这个问题吗?

0 个答案:

没有答案