I am trying to create a plotly graph using Scattermapbox with a dropdown box. The aim is for the dropdown to control the colorscale and labels associated with the scatter points. The data plots OK initially. When I select the second value in the dropdown the colors and labels change, but when I reselect the first value in the menu, which has the same properties as the initial plot, all but the first value has a non-grey colour.
Any ideas why this might be happening? I have included a simplified example below:
import plotly as py
import plotly.graph_objs as go
import copy
lat = [20, 30, 40]
lon = [0, 10, 30]
var1=[1, 2, -1]
var2=[10, 20, 30]
var1Str = [str(x) for x in var1]
var2Str = [str(x) for x in var2]
#%% plot points on a map
MAPBOX_TOKEN= USER TO INSERT TOKEN HERE
markerTemplate=dict(
size=9,
color=var1,
colorbar=dict(
titleside = 'right',
),
colorscale='Viridis')
marker1=copy.deepcopy(markerTemplate)
marker1['color']=var1
marker1['cmin']=-1
marker1['cmax']=2
marker2=copy.deepcopy(markerTemplate)
marker2['color']=var2
marker2['cmin']=10
marker2['cmax']=30
data = [
go.Scattermapbox(
lat=lat,
lon=lon,
mode='markers',
marker=marker1,
text=var1Str,
)
]
layout = go.Layout(
mapbox=dict(
accesstoken=MAPBOX_TOKEN,
bearing=0,
center=dict(
lat=15,
lon=0
),
zoom=0.75
),
)
updatemenus=list([
dict(
buttons=list([
dict(
args=[{'marker': marker1}, {'text': var1Str}],
label='var1',
method='update'
),
dict(
args=[{'marker': marker2},{'text': var2Str}],
label='var2',
method='update'
),
]),
direction = 'down',
pad = {'r': 10, 't': 10},
showactive = False,
x = 0.1,
xanchor = 'left',
y = 1.1,
yanchor = 'top'
),
])
layout['updatemenus'] = updatemenus
fig = dict(data=data, layout=layout)
py.offline.plot(fig, filename='ScatterMapBox_TEST.html')