Hello,
I have a data in csv which has Data,Value,Lat,Long
i want to have the Data
displayed as legend and values
as markers. I have a similar map created in folium
i need something like this as legend
Please let me know how can i do this
Hello,
I have a data in csv which has Data,Value,Lat,Long
i want to have the Data
displayed as legend and values
as markers. I have a similar map created in folium
i need something like this as legend
Please let me know how can i do this
This question is basically on how to create legend and group data…sorry if i am not clear
@rasika You can associate a legend to a mapbox map, like in your posted image as follows:
pandas.DataFrame
go.Scattermapbox
trace, and set trace name=group_name
help(go.Layout.legend)
.Example:
import plotly.graph_objects as go
import pandas as pd
mapbox_access_token = open(".mapbox_token").read()# .mapbox_token is a file containing your mapbox token
lats = [45.5017, 43.761539, 45.411171, 46.829853, 46.498390]
lons = [-73.5673, -79.411079, -75.6981201, -71.2540, -66.159668]
value = [ 12.35, 21, 17.9, 24, 15]
#locs = ['Montreal', 'Toronto', 'Ottawa', 'Quebec', 'New Brunswick']
group = ['A', 'B', 'A', 'C', 'B']
d = dict(lat =lats, lon=lons, value=value, group =group)
df = pd.DataFrame(d)
gb = df.groupby(['group'])
group_name = list(set(df['group']))
fig = go.Figure()
for gr in group_name:
my_gr = gb.get_group(gr)
fig.add_trace(go.Scattermapbox(lon=my_gr['lon'],
lat=my_gr['lat'],
customdata = my_gr['value'],
hovertemplate = '<b>Value</b>: %{customdata}',
name=gr,
mode='markers',
marker=dict(size=14),
))
fig.update_layout(width =800, height=600,
hovermode='closest',
mapbox=go.layout.Mapbox(
accesstoken=mapbox_access_token,
bearing=0,
center=go.layout.mapbox.Center(
lat=45,
lon=-75
),
pitch=0,
zoom=4,
style='basic'
)
);
fig.update_layout(legend = dict(bordercolor='rgb(100,100,100)',
borderwidth=2,
itemclick= 'toggleothers',# when you are clicking an item in legend all that are not in the same group are hidden
x=0.91,
y=1))
fig.show()
Thanks a million…it works…Plotly is colossally brilliant…30000 times better than folium…
Can you please help me in this query Change hover text color