@@ -1303,12 +1303,10 @@ def create_contribution_choropleth(data: pd.DataFrame):
1303
1303
z = avg_data ['total_percentage' ],
1304
1304
locationmode = 'ISO-3' ,
1305
1305
colorscale = 'Viridis' ,
1306
- # colorscale=[[0, 'rgb(10, 49, 97)'], [1, 'rgb(238, 28, 37)']],
1307
1306
reversescale = False ,
1308
1307
zmid = None , # Let plotly handle the midpoint
1309
1308
zmin = color_range [0 ],
1310
1309
zmax = color_range [1 ],
1311
- # legendwidth = 20,
1312
1310
hovertemplate = (
1313
1311
"<b>%{customdata[0]}</b> (%{location})<br>" +
1314
1312
"Avg Contribution: %{z:.2f}%<br>" +
@@ -1322,14 +1320,9 @@ def create_contribution_choropleth(data: pd.DataFrame):
1322
1320
y = 0.02 ,
1323
1321
xanchor = "left" ,
1324
1322
x = 0.1 ,
1325
- # tickangle =0,
1326
- # tickformat = ".2f",
1327
1323
ticklabelstep = 4 ,
1328
1324
ticksuffix = "%" ,
1329
- # titleside="right",
1330
1325
tickmode = "linear" ,
1331
- # xanchor ='right',
1332
- # yanchor ='bottom',
1333
1326
tick0 = color_range [0 ],
1334
1327
dtick = max (0.5 , (color_range [1 ] - color_range [0 ]) / 10 )
1335
1328
),
@@ -1347,88 +1340,101 @@ def create_contribution_choropleth(data: pd.DataFrame):
1347
1340
lakecolor = 'rgba(127,205,255,0.1)'
1348
1341
),
1349
1342
template = 'plotly_white' ,
1350
- height = 500 ,
1351
- margin = dict (l = 20 , r = 20 , t = 60 , b = 20 ),
1343
+ height = 550 , # Increased height to accommodate buttons
1344
+ margin = dict (l = 20 , r = 20 , t = 80 , b = 20 ), # Increased top margin for buttons
1352
1345
modebar_remove = ['zoom' , 'pan' , 'lasso' , 'select' ]
1353
1346
)
1354
1347
1355
- # Add dropdowns
1356
- button_layer_1_height = 1.02
1348
+ # Position buttons in top corners to avoid overlap
1357
1349
fig .update_layout (
1358
- updatemenus = [
1359
- dict (
1360
- buttons = list ([
1361
- dict (
1362
- args = ["colorscale" , "Viridis" ],
1363
- label = "Viridis" ,
1364
- method = "restyle"
1365
- ),
1366
- dict (
1367
- args = ["colorscale" , "Cividis" ],
1368
- label = "Cividis" ,
1369
- method = "restyle"
1370
- ),
1371
- dict (
1372
- args = ["colorscale" , "Reds" ],
1373
- label = "Reds" ,
1374
- method = "restyle"
1375
- ),
1376
- dict (
1377
- args = ["colorscale" , "Blues" ],
1378
- label = "Blues" ,
1379
- method = "restyle"
1380
- ),
1381
- dict (
1382
- args = ["colorscale" , "Greens" ],
1383
- label = "Greens" ,
1384
- method = "restyle"
1385
- ),
1386
- dict (
1387
- args = ["colorscale" , "Jet" ],
1388
- label = "Rainbow" ,
1389
- method = "restyle"
1390
- ),
1391
- ]),
1392
- direction = "down" ,
1393
- pad = {"r" : 10 , "t" : 10 },
1394
- showactive = True ,
1395
- x = 0.1 ,
1396
- xanchor = "left" ,
1397
- y = button_layer_1_height ,
1398
- yanchor = "top"
1399
- ),
1400
- dict (
1401
- buttons = list ([
1402
- dict (
1403
- args = ["reversescale" , False ],
1404
- label = "False" ,
1405
- method = "restyle"
1406
- ),
1407
- dict (
1408
- args = ["reversescale" , True ],
1409
- label = "True" ,
1410
- method = "restyle"
1411
- )
1412
- ]),
1413
- direction = "down" ,
1414
- pad = {"r" : 10 , "t" : 10 },
1415
- showactive = True ,
1416
- x = 0.37 ,
1417
- xanchor = "left" ,
1418
- y = button_layer_1_height ,
1419
- yanchor = "top"
1420
- ),
1421
- ]
1350
+ updatemenus = [
1351
+ dict (
1352
+ buttons = list ([
1353
+ dict (
1354
+ args = ["colorscale" , "Viridis" ],
1355
+ label = "Viridis" ,
1356
+ method = "restyle"
1357
+ ),
1358
+ dict (
1359
+ args = ["colorscale" , "Cividis" ],
1360
+ label = "Cividis" ,
1361
+ method = "restyle"
1362
+ ),
1363
+ dict (
1364
+ args = ["colorscale" , "Reds" ],
1365
+ label = "Reds" ,
1366
+ method = "restyle"
1367
+ ),
1368
+ dict (
1369
+ args = ["colorscale" , "Blues" ],
1370
+ label = "Blues" ,
1371
+ method = "restyle"
1372
+ ),
1373
+ dict (
1374
+ args = ["colorscale" , "Greens" ],
1375
+ label = "Greens" ,
1376
+ method = "restyle"
1377
+ ),
1378
+ dict (
1379
+ args = ["colorscale" , "Jet" ],
1380
+ label = "Rainbow" ,
1381
+ method = "restyle"
1382
+ ),
1383
+ ]),
1384
+ direction = "down" ,
1385
+ pad = {"r" : 10 , "t" : 10 },
1386
+ showactive = True ,
1387
+ x = 0.02 , # Left side
1388
+ xanchor = "left" ,
1389
+ y = 0.98 , # Top
1390
+ yanchor = "top"
1391
+ ),
1392
+ dict (
1393
+ buttons = list ([
1394
+ dict (
1395
+ args = ["reversescale" , False ],
1396
+ label = "Normal" ,
1397
+ method = "restyle"
1398
+ ),
1399
+ dict (
1400
+ args = ["reversescale" , True ],
1401
+ label = "Reversed" ,
1402
+ method = "restyle"
1403
+ )
1404
+ ]),
1405
+ direction = "down" ,
1406
+ pad = {"r" : 10 , "t" : 10 },
1407
+ showactive = True ,
1408
+ x = 0.98 , # Right side
1409
+ xanchor = "right" ,
1410
+ y = 0.98 , # Top
1411
+ yanchor = "top"
1412
+ ),
1413
+ ],
1414
+ annotations = [
1415
+ dict (
1416
+ text = "Colorscale" ,
1417
+ x = 0.02 ,
1418
+ xref = "paper" ,
1419
+ y = 1.02 ,
1420
+ yref = "paper" ,
1421
+ align = "left" ,
1422
+ showarrow = False ,
1423
+ font = dict (size = 12 )
1424
+ ),
1425
+ dict (
1426
+ text = "Reverse" ,
1427
+ x = 0.98 ,
1428
+ xref = "paper" ,
1429
+ y = 1.02 ,
1430
+ yref = "paper" ,
1431
+ align = "right" ,
1432
+ showarrow = False ,
1433
+ font = dict (size = 12 )
1434
+ )
1435
+ ]
1422
1436
)
1423
1437
1424
- fig .update_layout (
1425
- annotations = [
1426
- dict (text = "Colorscale" , x = 0 , xref = "paper" , y = 1.04 , yref = "paper" ,
1427
- align = "left" , showarrow = False ),
1428
- dict (text = "Reverse Colorscale" , x = 0.25 , xref = "paper" , y = 1.04 ,
1429
- yref = "paper" , showarrow = False )
1430
- ])
1431
-
1432
1438
return fig
1433
1439
1434
1440
def create_summary_dataframe (data : pd .DataFrame , mode : str ) -> pd .DataFrame :
0 commit comments