Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 24730c3

Browse filesBrowse files
authored
Merge pull request #4726 from plotly/maplibre-tests_with-px
Add new `map` options to `px` and update plotly.js/master at 056799dfc705a4533935ae3169cc94d35bc44830
2 parents 2bd7dc6 + 4fc6d81 commit 24730c3
Copy full SHA for 24730c3

File tree

8 files changed

+210
-9
lines changed
Filter options

8 files changed

+210
-9
lines changed

‎doc/apidoc/plotly.express.rst

Copy file name to clipboardExpand all lines: doc/apidoc/plotly.express.rst
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ plotly's high-level API for rapid figure generation. ::
1818
scatter_3d
1919
scatter_polar
2020
scatter_ternary
21+
scatter_map
2122
scatter_mapbox
2223
scatter_geo
2324
line
2425
line_3d
2526
line_polar
2627
line_ternary
28+
line_map
2729
line_mapbox
2830
line_geo
2931
area
@@ -45,9 +47,11 @@ plotly's high-level API for rapid figure generation. ::
4547
parallel_coordinates
4648
parallel_categories
4749
choropleth
50+
choropleth_map
4851
choropleth_mapbox
4952
density_contour
5053
density_heatmap
54+
density_map
5155
density_mapbox
5256
imshow
5357
set_mapbox_access_token

‎packages/python/plotly/plotly/_subplots.py

Copy file name to clipboardExpand all lines: packages/python/plotly/plotly/_subplots.py
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# little differently.
99
import collections
1010

11-
_single_subplot_types = {"scene", "geo", "polar", "ternary", "mapbox"}
11+
_single_subplot_types = {"scene", "geo", "polar", "ternary", "map", "mapbox"}
1212
_subplot_types = set.union(_single_subplot_types, {"xy", "domain"})
1313

1414
# For most subplot types, a trace is associated with a particular subplot
@@ -20,7 +20,7 @@
2020
# the trace property is just named `subplot`. For example setting
2121
# the `scatterpolar.subplot` property to `polar3` associates the scatterpolar
2222
# trace with the third polar subplot in the figure
23-
_subplot_prop_named_subplot = {"polar", "ternary", "mapbox"}
23+
_subplot_prop_named_subplot = {"polar", "ternary", "map", "mapbox"}
2424

2525

2626
# Named tuple to hold an xaxis/yaxis pair that represent a single subplot
@@ -150,7 +150,8 @@ def make_subplots(
150150
- 'scene': 3D Cartesian subplot for scatter3d, cone, etc.
151151
- 'polar': Polar subplot for scatterpolar, barpolar, etc.
152152
- 'ternary': Ternary subplot for scatterternary
153-
- 'mapbox': Mapbox subplot for scattermapbox
153+
- 'map': Map subplot for scattermap, choroplethmap and densitymap
154+
- 'mapbox': Mapbox subplot for scattermapbox, choroplethmapbox and densitymapbox
154155
- 'domain': Subplot type for traces that are individually
155156
positioned. pie, parcoords, parcats, etc.
156157
- trace type: A trace type which will be used to determine

‎packages/python/plotly/plotly/express/__init__.py

Copy file name to clipboardExpand all lines: packages/python/plotly/plotly/express/__init__.py
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@
1717
scatter_3d,
1818
scatter_polar,
1919
scatter_ternary,
20+
scatter_map,
2021
scatter_mapbox,
2122
scatter_geo,
2223
line,
2324
line_3d,
2425
line_polar,
2526
line_ternary,
27+
line_map,
2628
line_mapbox,
2729
line_geo,
2830
area,
@@ -46,7 +48,9 @@
4648
icicle,
4749
funnel,
4850
funnel_area,
51+
choropleth_map,
4952
choropleth_mapbox,
53+
density_map,
5054
density_mapbox,
5155
)
5256

@@ -67,16 +71,19 @@
6771
"scatter_3d",
6872
"scatter_polar",
6973
"scatter_ternary",
74+
"scatter_map",
7075
"scatter_mapbox",
7176
"scatter_geo",
7277
"scatter_matrix",
7378
"density_contour",
7479
"density_heatmap",
80+
"density_map",
7581
"density_mapbox",
7682
"line",
7783
"line_3d",
7884
"line_polar",
7985
"line_ternary",
86+
"line_map",
8087
"line_mapbox",
8188
"line_geo",
8289
"parallel_coordinates",
@@ -91,6 +98,7 @@
9198
"histogram",
9299
"ecdf",
93100
"choropleth",
101+
"choropleth_map",
94102
"choropleth_mapbox",
95103
"pie",
96104
"sunburst",

‎packages/python/plotly/plotly/express/_chart_types.py

Copy file name to clipboardExpand all lines: packages/python/plotly/plotly/express/_chart_types.py
+147Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,6 +1211,153 @@ def line_geo(
12111211
line_geo.__doc__ = make_docstring(line_geo)
12121212

12131213

1214+
def scatter_map(
1215+
data_frame=None,
1216+
lat=None,
1217+
lon=None,
1218+
color=None,
1219+
text=None,
1220+
hover_name=None,
1221+
hover_data=None,
1222+
custom_data=None,
1223+
size=None,
1224+
animation_frame=None,
1225+
animation_group=None,
1226+
category_orders=None,
1227+
labels=None,
1228+
color_discrete_sequence=None,
1229+
color_discrete_map=None,
1230+
color_continuous_scale=None,
1231+
range_color=None,
1232+
color_continuous_midpoint=None,
1233+
opacity=None,
1234+
size_max=None,
1235+
zoom=8,
1236+
center=None,
1237+
map_style=None,
1238+
title=None,
1239+
template=None,
1240+
width=None,
1241+
height=None,
1242+
) -> go.Figure:
1243+
"""
1244+
In a scatter map, each row of `data_frame` is represented by a
1245+
symbol mark on the map.
1246+
"""
1247+
return make_figure(args=locals(), constructor=go.Scattermap)
1248+
1249+
1250+
scatter_map.__doc__ = make_docstring(scatter_map)
1251+
1252+
1253+
def choropleth_map(
1254+
data_frame=None,
1255+
geojson=None,
1256+
featureidkey=None,
1257+
locations=None,
1258+
color=None,
1259+
hover_name=None,
1260+
hover_data=None,
1261+
custom_data=None,
1262+
animation_frame=None,
1263+
animation_group=None,
1264+
category_orders=None,
1265+
labels=None,
1266+
color_discrete_sequence=None,
1267+
color_discrete_map=None,
1268+
color_continuous_scale=None,
1269+
range_color=None,
1270+
color_continuous_midpoint=None,
1271+
opacity=None,
1272+
zoom=8,
1273+
center=None,
1274+
map_style=None,
1275+
title=None,
1276+
template=None,
1277+
width=None,
1278+
height=None,
1279+
) -> go.Figure:
1280+
"""
1281+
In a choropleth map, each row of `data_frame` is represented by a
1282+
colored region on the map.
1283+
"""
1284+
return make_figure(args=locals(), constructor=go.Choroplethmap)
1285+
1286+
1287+
choropleth_map.__doc__ = make_docstring(choropleth_map)
1288+
1289+
1290+
def density_map(
1291+
data_frame=None,
1292+
lat=None,
1293+
lon=None,
1294+
z=None,
1295+
hover_name=None,
1296+
hover_data=None,
1297+
custom_data=None,
1298+
animation_frame=None,
1299+
animation_group=None,
1300+
category_orders=None,
1301+
labels=None,
1302+
color_continuous_scale=None,
1303+
range_color=None,
1304+
color_continuous_midpoint=None,
1305+
opacity=None,
1306+
zoom=8,
1307+
center=None,
1308+
map_style=None,
1309+
radius=None,
1310+
title=None,
1311+
template=None,
1312+
width=None,
1313+
height=None,
1314+
) -> go.Figure:
1315+
"""
1316+
In a density map, each row of `data_frame` contributes to the intensity of
1317+
the color of the region around the corresponding point on the map
1318+
"""
1319+
return make_figure(
1320+
args=locals(), constructor=go.Densitymap, trace_patch=dict(radius=radius)
1321+
)
1322+
1323+
1324+
density_map.__doc__ = make_docstring(density_map)
1325+
1326+
1327+
def line_map(
1328+
data_frame=None,
1329+
lat=None,
1330+
lon=None,
1331+
color=None,
1332+
text=None,
1333+
hover_name=None,
1334+
hover_data=None,
1335+
custom_data=None,
1336+
line_group=None,
1337+
animation_frame=None,
1338+
animation_group=None,
1339+
category_orders=None,
1340+
labels=None,
1341+
color_discrete_sequence=None,
1342+
color_discrete_map=None,
1343+
zoom=8,
1344+
center=None,
1345+
map_style=None,
1346+
title=None,
1347+
template=None,
1348+
width=None,
1349+
height=None,
1350+
) -> go.Figure:
1351+
"""
1352+
In a line map, each row of `data_frame` is represented as
1353+
vertex of a polyline mark on the map.
1354+
"""
1355+
return make_figure(args=locals(), constructor=go.Scattermap)
1356+
1357+
1358+
line_map.__doc__ = make_docstring(line_map)
1359+
1360+
12141361
def scatter_mapbox(
12151362
data_frame=None,
12161363
lat=None,

‎packages/python/plotly/plotly/express/_core.py

Copy file name to clipboardExpand all lines: packages/python/plotly/plotly/express/_core.py
+40-6Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,11 @@ def make_trace_kwargs(args, trace_spec, trace_data, mapping_labels, sizeref):
426426
# as a list of row lists, which is what we want
427427
trace_patch["customdata"] = trace_data[customdata_cols]
428428
elif attr_name == "color":
429-
if trace_spec.constructor in [go.Choropleth, go.Choroplethmapbox]:
429+
if trace_spec.constructor in [
430+
go.Choropleth,
431+
go.Choroplethmap,
432+
go.Choroplethmapbox,
433+
]:
430434
trace_patch["z"] = trace_data[attr_value]
431435
trace_patch["coloraxis"] = "coloraxis1"
432436
mapping_labels[attr_label] = "%{z}"
@@ -532,6 +536,9 @@ def configure_axes(args, constructor, fig, orders):
532536
go.Scatterpolar: configure_polar_axes,
533537
go.Scatterpolargl: configure_polar_axes,
534538
go.Barpolar: configure_polar_axes,
539+
go.Scattermap: configure_map,
540+
go.Choroplethmap: configure_map,
541+
go.Densitymap: configure_map,
535542
go.Scattermapbox: configure_mapbox,
536543
go.Choroplethmapbox: configure_mapbox,
537544
go.Densitymapbox: configure_mapbox,
@@ -739,6 +746,20 @@ def configure_mapbox(args, fig, orders):
739746
)
740747

741748

749+
def configure_map(args, fig, orders):
750+
center = args["center"]
751+
if not center and "lat" in args and "lon" in args:
752+
center = dict(
753+
lat=args["data_frame"][args["lat"]].mean(),
754+
lon=args["data_frame"][args["lon"]].mean(),
755+
)
756+
fig.update_maps(
757+
center=center,
758+
zoom=args["zoom"],
759+
style=args["map_style"],
760+
)
761+
762+
742763
def configure_geo(args, fig, orders):
743764
fig.update_geos(
744765
center=args["center"],
@@ -1911,15 +1932,21 @@ def infer_config(args, constructor, trace_patch, layout_patch):
19111932
else:
19121933
trace_patch["texttemplate"] = "%{" + letter + ":" + args["text_auto"] + "}"
19131934

1914-
if constructor in [go.Histogram2d, go.Densitymapbox]:
1935+
if constructor in [go.Histogram2d, go.Densitymap, go.Densitymapbox]:
19151936
show_colorbar = True
19161937
trace_patch["coloraxis"] = "coloraxis1"
19171938

19181939
if "opacity" in args:
19191940
if args["opacity"] is None:
19201941
if "barmode" in args and args["barmode"] == "overlay":
19211942
trace_patch["marker"] = dict(opacity=0.5)
1922-
elif constructor in [go.Densitymapbox, go.Pie, go.Funnel, go.Funnelarea]:
1943+
elif constructor in [
1944+
go.Densitymap,
1945+
go.Densitymapbox,
1946+
go.Pie,
1947+
go.Funnel,
1948+
go.Funnelarea,
1949+
]:
19231950
trace_patch["opacity"] = args["opacity"]
19241951
else:
19251952
trace_patch["marker"] = dict(opacity=args["opacity"])
@@ -1937,7 +1964,7 @@ def infer_config(args, constructor, trace_patch, layout_patch):
19371964
modes.add("lines")
19381965
trace_patch["mode"] = "+".join(sorted(modes))
19391966
elif constructor != go.Splom and (
1940-
"symbol" in args or constructor == go.Scattermapbox
1967+
"symbol" in args or constructor in [go.Scattermap, go.Scattermapbox]
19411968
):
19421969
trace_patch["mode"] = "markers" + ("+text" if args["text"] else "")
19431970

@@ -2154,7 +2181,9 @@ def make_figure(args, constructor, trace_patch=None, layout_patch=None):
21542181
go.Parcats,
21552182
go.Parcoords,
21562183
go.Choropleth,
2184+
go.Choroplethmap,
21572185
go.Choroplethmapbox,
2186+
go.Densitymap,
21582187
go.Densitymapbox,
21592188
go.Histogram2d,
21602189
go.Sunburst,
@@ -2198,7 +2227,8 @@ def make_figure(args, constructor, trace_patch=None, layout_patch=None):
21982227
):
21992228
trace.update(marker=dict(color=m.val_map[val]))
22002229
elif (
2201-
trace_spec.constructor in [go.Choropleth, go.Choroplethmapbox]
2230+
trace_spec.constructor
2231+
in [go.Choropleth, go.Choroplethmap, go.Choroplethmapbox]
22022232
and m.variable == "color"
22032233
):
22042234
trace.update(
@@ -2281,7 +2311,11 @@ def make_figure(args, constructor, trace_patch=None, layout_patch=None):
22812311
)
22822312

22832313
if show_colorbar:
2284-
colorvar = "z" if constructor in [go.Histogram2d, go.Densitymapbox] else "color"
2314+
colorvar = (
2315+
"z"
2316+
if constructor in [go.Histogram2d, go.Densitymap, go.Densitymapbox]
2317+
else "color"
2318+
)
22852319
range_color = args["range_color"] or [None, None]
22862320

22872321
colorscale_validator = ColorscaleValidator("colorscale", "make_figure")

‎packages/python/plotly/plotly/express/_doc.py

Copy file name to clipboardExpand all lines: packages/python/plotly/plotly/express/_doc.py
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,11 @@
531531
"Dict keys are `'lat'` and `'lon'`",
532532
"Sets the center point of the map.",
533533
],
534+
map_style=[
535+
"str (default `'basic'`)",
536+
"Identifier of base map style.",
537+
"Allowed values are `'basic'`, `'carto-darkmatter'`, `'carto-darkmatter-nolabels'`, `'carto-positron'`, `'carto-positron-nolabels'`, `'carto-voyager'`, `'carto-voyager-nolabels'`, `'dark'`, `'light'`, `'open-street-map'`, `'outdoors'`, `'satellite'`, `'satellite-streets'`, `'streets'`, `'white-bg'`.",
538+
],
534539
mapbox_style=[
535540
"str (default `'basic'`, needs Mapbox API token)",
536541
"Identifier of base map style, some of which require a Mapbox or Stadia Maps API token to be set using `plotly.express.set_mapbox_access_token()`.",

‎packages/python/plotly/plotly/subplots.py

Copy file name to clipboardExpand all lines: packages/python/plotly/plotly/subplots.py
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ def make_subplots(
114114
- 'scene': 3D Cartesian subplot for scatter3d, cone, etc.
115115
- 'polar': Polar subplot for scatterpolar, barpolar, etc.
116116
- 'ternary': Ternary subplot for scatterternary
117+
- 'map': Map subplot for scattermap
117118
- 'mapbox': Mapbox subplot for scattermapbox
118119
- 'domain': Subplot type for traces that are individually
119120
positioned. pie, parcoords, parcats, etc.

‎packages/python/plotly/templategen/utils/__init__.py

Copy file name to clipboardExpand all lines: packages/python/plotly/templategen/utils/__init__.py
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
("scattergl", "marker"),
2121
("scatter3d", "line"),
2222
("scatter3d", "marker"),
23+
("scattermap", "marker"),
2324
("scattermapbox", "marker"),
2425
("scatterternary", "marker"),
2526
("scattercarpet", "marker"),

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.