Hi, as I’m learning Dash another question come into my way.
I’m trying to plot a map with some routes, I have a dataframe like this:
Latitude Longitude Route number Stop Number
xxx xxxx 1 1
xxx xxxx 1 2
xxx xxxx 1 3
xxx xxxx 2 1
xxx xxxx 2 2
xxx xxxx 2 3
I’m currently able to plot the dots on the map and they display the correct way using MapBox, now what I want to do is to create lines between them based on the Stop Number. Like in the table there would be a line in some color that goes from stop number 1 to 2 then 3 and another line doing the same with a differnt color for route number 2. I think a way to do this is to create layers, is this the only approach? My code looks like this taking away some parts:
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
server = app.server
app.title = 'NYC Wi-Fi Hotspots'
layout_map = dict(
autosize=True,
height=800,
font=dict(color="#191A1A"),
titlefont=dict(color="#191A1A", size=14),
margin=dict(
l=10,
r=35,
b=35,
t=10
),
hovermode="closest",
plot_bgcolor="#fffcfc",
paper_bgcolor="#fffcfc",
legend=dict(font=dict(size=10), orientation="h"),
title="BCN Map",
mapbox=dict(
accesstoken=mapbox_access_token,
style="dark",
center=dict(
lon=2.200626,
lat=41.442931
),
zoom=10
)
)
# GENMAP
def gen_map(data):
return {
"data": [
{
"type": "scattermapbox",
"lat": list(data["Latitude"]),
"lon": list(data["Longitude"]),
"hoverinfo": "text",
"hovertext":[
[
"""
Name: {}<br>
Type: {}<br>
Provider:{}
""".format(i, j, k)
] for i, j, k in zip(data['Name'], data['Type'], data['Provider'])
],
"mode": "markers+lines",
"name": list(data['Name']),
"marker":{
"size": 10,
"opacity": 0.7
}
}
],
"layout": layout_map
}
Thanks and if you know any other api for plotting on maps that show information like MapBox it would be much apreciated