just starting to program in Python, and faced the following problems when trying to plot three points moving in a map, as the time progresses. Not sure if this is a bug from plotly or it is just me....
Even though I want to represent three different points, (i.e. 3 vehicles), movements within the map, if the dataframe starts with only one of them (only vehicle A moving), then the graph is not able to add any of the remaining two when they should pop up (B and C start displacing later). On the contrary, if the graph starts with the three vehicles moving at the same time, made with the purpose of representing the three of them from the start, then, the graph is not capable to become showing less points when one of them should stop being displayed. All the time three points will be showing at all times, even though from three moving vehicles should pass to only two and finally only one.
Is there any way please the graph can adapt and pass from representing for example from one point to three, then to only two, and finally back to only one (erasing or popping up the old/new points as the time frame progresses).
I attach below one example of code where it starts showing the three points (vehicles) moving at the same time, but then the graph is not capable of stopped showing three points when it should show only one.
import plotly.express as px
import pandas as pd
data = {'time': ['2023-01-01', '2023-01-01', '2023-01-01', '2023-01-02', '2023-01-03', '2023-01-03','2023-01-04', '2023-01-04', '2023-01-05', '2023-01-05', '2023-01-06', '2023-01-06', '2023-01-07', '2023-01-07', '2023-01-08', '2023-01-08', '2023-01-09', '2023-01-10', '2023-01-10', '2023-01-10', '2023-01-11', '2023-01-12', '2023-01-13'], 'lat': [37.7749, 37.7740, 37.7730, 37.7720, 37.7710, 37.7700,37.7690, 37.7680, 37.7670, 37.7660, 37.7650, 37.7640, 37.7630, 37.7620, 37.7610, 37.7600, 37.7590, 37.7580,37.7570, 37.7560, 37.7550, 37.7540, 37.7530], 'lon': [-122.4194, -122.4184, -122.4174, -122.4164, -122.4154, -122.4144, -122.4134, -122.4124, -122.4114, -122.4104, -122.4094, -122.4084, -122.4074, -122.4064, -122.4054, -122.4044, -122.4034, -122.4024,-122.4014, -122.4004, -122.3994, -122.3984, -122.3974],'point': ['A', 'B', 'C', 'C', 'A', 'B','C', 'B', 'A', 'B', 'A', 'B','A', 'B', 'A', 'B', 'A', 'B', 'A', 'C', 'C', 'C', 'C']}
df = pd.DataFrame(data)
fig = px.scatter_mapbox(df, lat='lat', lon='lon', color='point', size_max=15, zoom=10, mapbox_style="carto-positron", animation_frame='time')
fig.update_layout(autosize=False, width=1200, height=800)
fig.layout.updatemenus[0].buttons[0].args[1]['frame']['duration'] = 1000 # milisegundos
fig.show()
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745048392a4608234.html
评论列表(0条)