Hi!
I’m doing a choropleth mapbox plot with a list of buttons, and I would like to be able to specify cmin and cmax for each of the buttons.
I’ve followed @empet s guide here to do my plot and it looks good so far. The only thing I need is being able to specify cmin and cmax for each of my keys in the button.
def custom_cmax(x):
if '_House' in x:
return 20
else:
return 100
buttons = []
for key in df_collection.keys():
button = dict(method = "restyle",
args = [{
'z': [ df_collection[key]['Percentage']],
'custom_data' : [[['CustPostalName', 'N']]],
'coloraxis' : {'cmax' : custom_cmax(key)},
}],
label = ' '.join(key.split('_')))
buttons.append(button)
fig = px.choropleth_mapbox(data_frame=df_collection[key],
geojson=geojson,
locations='CustPostalCdAggr',
featureidkey='properties.postal_code',
color="Percentage",
mapbox_style="carto-positron",
custom_data=['CustPostalName', 'N'],
zoom=5, center = {"lat": 55.676098, "lon": 12.568337})
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.update_traces(
hovertemplate="<br>".join([
"<b>%{customdata[0]}</b>",
"Percentage of customers with loan:",
"%{z}",
"",
"N=%{customdata[1]}"
])
)
fig.update_layout(coloraxis_colorbar_thickness=23,
updatemenus=[dict(y=1,
x=0,
xanchor='right',
yanchor='top',
active=0,
buttons=buttons)
])
Clicking the buttons does not change the cmax and furthermore, it makes the colorbar look weird. Have someone tried this before?