Plotly анимация Python, PlotlyRequestError: поле рисунка недействительно - PullRequest
0 голосов
/ 19 мая 2018

Я пытаюсь анимировать данные временных рядов с помощью сюжета.Я успешно создал неанимированный график, используя те же данные: 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')]

Кто-нибудь может мне помочь выяснить это?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...