@@ -1183,6 +1183,157 @@ def cohorts(
11831183
11841184 return df_cohorts
11851185
1186+ @check_types
1187+ @doc (
1188+ summary = """
1189+ Plot markers on a map showing sample locations
1190+ as a Mapbox scatter plot.
1191+ """ ,
1192+ parameters = dict (
1193+ kwargs = "Passed through to px.scatter_mapbox()." ,
1194+ ),
1195+ )
1196+ def plot_sample_location_mapbox (
1197+ self ,
1198+ * ,
1199+ sample_sets : Optional [base_params .sample_sets ],
1200+ sample_query : Optional [base_params .sample_query ] = None ,
1201+ sample_query_options : Optional [base_params .sample_query_options ] = None ,
1202+ marker_size : plotly_params .marker_size = 10 ,
1203+ color : plotly_params .color = "admin1_name" ,
1204+ color_discrete_sequence : plotly_params .color_discrete_sequence = px .colors .qualitative .Prism ,
1205+ category_orders : plotly_params .category_order = None ,
1206+ hover_name : plotly_params .hover_name = "location" ,
1207+ zoom : plotly_params .zoom = None ,
1208+ width : plotly_params .fig_width = 800 ,
1209+ height : plotly_params .fig_height = 600 ,
1210+ show : plotly_params .show = True ,
1211+ renderer : plotly_params .renderer = None ,
1212+ ** kwargs ,
1213+ ) -> plotly_params .figure :
1214+ # Get the sample metadata.
1215+ df_samples = self .sample_metadata (
1216+ sample_sets = sample_sets ,
1217+ sample_query = sample_query ,
1218+ sample_query_options = sample_query_options ,
1219+ )
1220+
1221+ # Set the location columns to use from the sample metadata.
1222+ location_columns = [
1223+ "country" ,
1224+ "admin1_iso" ,
1225+ "admin1_name" ,
1226+ "admin2_name" ,
1227+ "location" ,
1228+ "latitude" ,
1229+ "longitude" ,
1230+ ]
1231+
1232+ # Trim and dedupe the sample locations.
1233+ # Sort by `color` column by default, which can be overridden via category_orders.
1234+ df_locations = df_samples [location_columns ].drop_duplicates ().sort_values (color )
1235+
1236+ fig = px .scatter_mapbox (
1237+ df_locations ,
1238+ lat = "latitude" ,
1239+ lon = "longitude" ,
1240+ mapbox_style = "open-street-map" ,
1241+ zoom = zoom ,
1242+ color = color ,
1243+ category_orders = category_orders ,
1244+ color_discrete_sequence = color_discrete_sequence ,
1245+ hover_name = hover_name ,
1246+ hover_data = location_columns ,
1247+ width = width ,
1248+ height = height ,
1249+ ** kwargs ,
1250+ )
1251+
1252+ # Set the size of the markers.
1253+ fig .update_traces (marker = dict (size = marker_size ))
1254+
1255+ if show : # pragma: no cover
1256+ fig .show (renderer = renderer )
1257+ return None
1258+ else :
1259+ return fig
1260+
1261+ @check_types
1262+ @doc (
1263+ summary = """
1264+ Plot markers on a map showing sample locations
1265+ as a geographic scatter plot.
1266+ """ ,
1267+ parameters = dict (
1268+ kwargs = "Passed through to px.scatter_mapbox()." ,
1269+ ),
1270+ )
1271+ def plot_sample_location_geo (
1272+ self ,
1273+ * ,
1274+ sample_sets : Optional [base_params .sample_sets ],
1275+ sample_query : Optional [base_params .sample_query ] = None ,
1276+ sample_query_options : Optional [base_params .sample_query_options ] = None ,
1277+ marker_size : plotly_params .marker_size = 10 ,
1278+ color : plotly_params .color = "admin1_name" ,
1279+ color_discrete_sequence : plotly_params .color_discrete_sequence = px .colors .qualitative .Prism ,
1280+ category_orders : plotly_params .category_order = None ,
1281+ hover_name : plotly_params .hover_name = "location" ,
1282+ fitbounds : plotly_params .fitbounds = "locations" ,
1283+ scope : plotly_params .scope = "world" ,
1284+ width : plotly_params .fig_width = 800 ,
1285+ height : plotly_params .fig_height = 600 ,
1286+ show : plotly_params .show = True ,
1287+ renderer : plotly_params .renderer = None ,
1288+ ** kwargs ,
1289+ ) -> plotly_params .figure :
1290+ # Get the sample metadata.
1291+ df_samples = self .sample_metadata (
1292+ sample_sets = sample_sets ,
1293+ sample_query = sample_query ,
1294+ sample_query_options = sample_query_options ,
1295+ )
1296+
1297+ # Set the location columns to use from the sample metadata.
1298+ location_columns = [
1299+ "country" ,
1300+ "admin1_iso" ,
1301+ "admin1_name" ,
1302+ "admin2_name" ,
1303+ "location" ,
1304+ "latitude" ,
1305+ "longitude" ,
1306+ ]
1307+
1308+ # Trim and dedupe the sample locations.
1309+ # Sort by `color` column by default, which can be overridden via category_orders.
1310+ df_locations = df_samples [location_columns ].drop_duplicates ().sort_values (color )
1311+
1312+ fig = px .scatter_geo (
1313+ df_locations ,
1314+ lat = "latitude" ,
1315+ lon = "longitude" ,
1316+ scope = scope ,
1317+ height = height ,
1318+ width = width ,
1319+ color = color ,
1320+ hover_name = hover_name ,
1321+ hover_data = location_columns ,
1322+ category_orders = category_orders ,
1323+ color_discrete_sequence = color_discrete_sequence ,
1324+ fitbounds = fitbounds ,
1325+ ** kwargs ,
1326+ )
1327+
1328+ # Set the size of the markers.
1329+ fig .update_traces (marker = dict (size = marker_size ))
1330+
1331+ if show : # pragma: no cover
1332+ fig .show (renderer = renderer )
1333+ return None
1334+ else :
1335+ return fig
1336+
11861337
11871338def locate_cohorts (* , cohorts , data ):
11881339 # Build cohort dictionary where key=cohort_id, value=loc_coh.
0 commit comments