poltly express`sctity_mapbox`带有`animation_frame`和'颜色'
如果具有带有列的数据:“ e_lat”,“ e_lon”,“année”和“expéditeur”。 我正在尝试制作一个scats_mapbox,并用“Année”动画制作框架,并基于'expéditeur'颜色(这是分类的,是人的名字)。
# I created a row df['_color'] = df['Expéditeur'] because in the end I want to change the way _color is defined.
fig = px.scatter_mapbox(df,
lat='e_lat',
lon='e_lon',
hover_name='Ville Expéditeur',
hover_data=['Expéditeur', 'Destinataire', 'Ville Expéditeur', 'Année'],
animation_frame='Année',
mapbox_style='carto-positron',
zoom=4,
color='_color',
)
fig.show()
问题是,我的麻烦是我得到了类似的东西这 : (只有第一种颜色显示的点) 但缺少一些要点。
如果我评论
animation_frame ='année'',
,我会得到:
我做了很多研究完全相同并且有不同的结果([例如](例如]( https://towardsdatascience.com/how-to-animate-scatterplots-mapbox-mapbox-usish-plotly-plotly-3bb49fe6a5d ,此stackoverflow问题,...)
我的情节lib是最新的。 。
我在这里做错了什么?很多。
[编辑] 实际上,这与这里(未解决)。 这似乎是因为A 已记录的plotly 的错误。 “如果所有颜色都用于第一帧,则问题消失了。”
我通过添加“假数据”(在地图的范围之外)解决了它:在动画的第一帧中,每种颜色一个。
new_rows = []
for color in df['_color'].unique():
new_row = {'_color': color, 'Année': df['Année'].min(), 'lat': 0, 'lon': 0}
new_rows.append(new_row)
df = df.append(new_rows, ignore_index=True)
希望这对某人有帮助。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
实际上,这与这里(未解决)。
这似乎是因为A 已记录的plotly 的错误。
“如果所有颜色都用于第一帧,则问题消失了。”
我通过添加“假数据”(在地图的范围之外)解决了它:在动画的第一帧中,每种颜色一个。
希望这对某人有帮助。
In fact it's exaclty the same problem than here (not resolved).
This seems to be because of a documented bug of Plotly.
"If all colors are used for the first frame, the problem disappears."
I solved it by adding "fake data" (outside of the scope of the map) : one for each color, in the first frame of the animation.
Hope this will help someone.