Scatter_Mapbox with same legend. How can I change the legend when change value/click button?

hi,
Having two different columns which have different values,name is TAC and LAC. Creating scatter_mapbox two different map and can click buttom, showing diffent location and howover data. But doesnt not change lagend value between two map so doesnt change color.

df1 including some texts which are ‘SITE’, ‘TAC’, ‘PLANNER’, ‘CITY’, ‘CPSUBREGION’,‘LAC’.

TAC-LAC two different value to changing map points colour

Blockquote


style=['open-street-map', 'white-bg', 'carto-positron', 'carto-darkmatter', 'stamen- terrain', 'stamen-toner', 'stamen-watercolor']

color_sytle=['aggrnyl', 'agsunset', 'algae', 'amp', 'armyrose', 'balance',
 'blackbody', 'bluered', 'blues', 'blugrn', 'bluyl', 'brbg',
 'brwnyl', 'bugn', 'bupu', 'burg', 'burgyl', 'cividis', 'curl',
 'darkmint', 'deep', 'delta', 'dense', 'earth', 'edge', 'electric',
 'emrld', 'fall', 'geyser', 'gnbu', 'gray', 'greens', 'greys',
 'haline', 'hot', 'hsv', 'ice', 'icefire', 'inferno', 'jet',
 'magenta', 'magma', 'matter', 'mint', 'mrybm', 'mygbm', 'oranges',
 'orrd', 'oryel', 'oxy', 'peach', 'phase', 'picnic', 'pinkyl',
 'piyg', 'plasma', 'plotly3', 'portland', 'prgn', 'pubu', 'pubugn',
 'puor', 'purd', 'purp', 'purples', 'purpor', 'rainbow', 'rdbu',
 'rdgy', 'rdpu', 'rdylbu', 'rdylgn', 'redor', 'reds', 'solar',
 'spectral', 'speed', 'sunset', 'sunsetdark', 'teal', 'tealgrn',
 'tealrose', 'tempo', 'temps', 'thermal', 'tropic', 'turbid',
 'turbo', 'twilight', 'viridis', 'ylgn', 'ylgnbu', 'ylorbr',
 'ylorrd']

fig = px.scatter_mapbox(df1, lat='LAT', lon='LON',
                        mapbox_style=style[0] ,
                        color_continuous_scale=color_sytle[66],
                        hover_name='SITE', hover_data=['SITE', 'LAC', 'PLANNER', 'CITY', 'CPSUBREGION','TAC'],
                        color="LAC",
                        range_color=(df1["LAC"].min(),df1["LAC"].max()),
                        zoom=5 , height=600, width=900,
                        title="LAC-TAC Mapping Huawei"
                        
                        )




fig.add_trace(px.scatter_mapbox(df1, lat='LAT', lon='LON',
                        mapbox_style=style[0] ,
                        color_continuous_scale=color_sytle[66],
                        hover_name='SITE', hover_data=['SITE','TAC', 'PLANNER', 'CITY', 'CPSUBREGION', 'LAC'],
                        color="TAC",
                        labels=True,
                        range_color=(df1["TAC"].min(),df1["TAC"].max()),
                        zoom=5 , height=600, width=900
                        ).data[0])



fig.update_layout(
    updatemenus=[
        dict(
            type="buttons",
            direction="right",
            active=0,
            x=0.57,
            y=1.2,
            buttons=list([
                dict(label="LAC Harita Gösterimi",
                     method="update",                
                     args=[{"visible": [True,False]},
                           {"title": "LAC",
                            "annotations": []}]),

                dict(label="TAC Harita Gösterimi",
                     method="update",                     
                     args=[{"visible": [False,True]},
                           {"title": "TAC",
                            "annotations": []}]),   


            ]),
        )
    ])


fig.update_layout(margin={"r":0,"t":50,"l":0,"b":10})
fig.show()
fig.to_plotly_json()    
plot(fig, auto_open=True)


hi @REO
I’m not sure I understand your question. Would you like to update the legend of the second graph when the button of the first graph is clicked?

thanks for replying…
yes, I wanna update legend which button can be clicked. First button for LAC mapping, when click iti legend of LAC can be shown LAC value, there is no problem but when click for second TAC Map, legend doesnt not change/update , still is shown LAC legend

Can you please share a complete sample code that I can run in my computer and replicate the error you’re having?

df1=

|SITE | TAC | PLANNER | CITY | CPSUBREGION | LAC | LAT | LON|

|a | 8792 | a | a | a | 62246 | 37.5979 | 36.8635|
|b | 8792 | b | b | b | 62246 | 37.6002 | 36.8667|
|c | 8768 | c | c | c | 60550 | 38.5437 | 34.5173|
|d | 8793 | d | d | d | 62346 | 38.4954 | 36.799|
|e | 8793 | e | e | e | 62346 | 38.2455 | 36.9144|
|r | 8793 | r | r | r | 62346 | 38.34909444 | 37.03067222|

import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import plotly.express as px

style=['open-street-map', 'white-bg', 'carto-positron', 'carto-darkmatter', 'stamen- terrain', 'stamen-toner', 'stamen-watercolor']

color_sytle=['aggrnyl', 'agsunset', 'algae', 'amp', 'armyrose', 'balance',
 'blackbody', 'bluered', 'blues', 'blugrn', 'bluyl', 'brbg',
 'brwnyl', 'bugn', 'bupu', 'burg', 'burgyl', 'cividis', 'curl',
 'darkmint', 'deep', 'delta', 'dense', 'earth', 'edge', 'electric',
 'emrld', 'fall', 'geyser', 'gnbu', 'gray', 'greens', 'greys',
 'haline', 'hot', 'hsv', 'ice', 'icefire', 'inferno', 'jet',
 'magenta', 'magma', 'matter', 'mint', 'mrybm', 'mygbm', 'oranges',
 'orrd', 'oryel', 'oxy', 'peach', 'phase', 'picnic', 'pinkyl',
 'piyg', 'plasma', 'plotly3', 'portland', 'prgn', 'pubu', 'pubugn',
 'puor', 'purd', 'purp', 'purples', 'purpor', 'rainbow', 'rdbu',
 'rdgy', 'rdpu', 'rdylbu', 'rdylgn', 'redor', 'reds', 'solar',
 'spectral', 'speed', 'sunset', 'sunsetdark', 'teal', 'tealgrn',
 'tealrose', 'tempo', 'temps', 'thermal', 'tropic', 'turbid',
 'turbo', 'twilight', 'viridis', 'ylgn', 'ylgnbu', 'ylorbr',
 'ylorrd']




fig = px.scatter_mapbox(df1, lat='LAT', lon='LON',
                        mapbox_style=style[0] ,
                        color_continuous_scale=color_sytle[66],
                        hover_name='SITE', hover_data=['SITE', 'LAC', 'PLANNER', 'CITY', 'CPSUBREGION','TAC'],
                        color="LAC",
                        range_color=(df1["LAC"].min(),df1["LAC"].max()),
                        zoom=5 , height=600, width=900,
                        title="LAC-TAC Mapping Huawei"
                        
                        )


fig.add_trace(px.scatter_mapbox(df1, lat='LAT', lon='LON',
                        mapbox_style=style[0] ,
                        color_continuous_scale=color_sytle[66],
                        hover_name='SITE', hover_data=['SITE','TAC', 'PLANNER', 'CITY', 'CPSUBREGION', 'LAC'],
                        color="TAC",
                        range_color=(df1["TAC"].min(),df1["TAC"].max()),
                        
                        zoom=5 , height=600, width=900
                        ).data[0])

                    

fig.update_layout(
    updatemenus=[
        dict(
            type="buttons",
            direction="right",
            active=0,
            x=0.57,
            y=1.2,
            buttons=list([
                dict(label="LAC Harita Gösterimi",
                     method="update",                
                     args=[{"visible": [True,False]},
                           {"title": "LAC",
                            "annotations": []}]),

                dict(label="TAC Harita Gösterimi",
                     method="update",                     
                     args=[{"visible": [False,True]},
                           {"title": "TAC",
                            "annotations": []}]),   


            ]),
        )
    ])

fig.update_layout(margin={"r":0,"t":50,"l":0,"b":10})
fig.show()
fig.to_plotly_json()    
plot(fig, auto_open=True)