Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dd577a0

Browse files
add choropleth_mapbox to px
1 parent 93ec054 commit dd577a0

File tree

4 files changed

+48
-4
lines changed

4 files changed

+48
-4
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
treemap,
4545
funnel,
4646
funnel_area,
47+
choropleth_mapbox,
4748
)
4849

4950
from ._imshow import imshow
@@ -82,6 +83,7 @@
8283
"strip",
8384
"histogram",
8485
"choropleth",
86+
"choropleth_mapbox",
8587
"pie",
8688
"sunburst",
8789
"treemap",

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

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -842,15 +842,13 @@ def choropleth(
842842
hover_name=None,
843843
hover_data=None,
844844
custom_data=None,
845-
size=None,
846845
animation_frame=None,
847846
animation_group=None,
848847
category_orders={},
849848
labels={},
850849
color_continuous_scale=None,
851850
range_color=None,
852851
color_continuous_midpoint=None,
853-
size_max=None,
854852
projection=None,
855853
scope=None,
856854
center=None,
@@ -998,6 +996,42 @@ def scatter_mapbox(
998996
scatter_mapbox.__doc__ = make_docstring(scatter_mapbox)
999997

1000998

999+
def choropleth_mapbox(
1000+
data_frame=None,
1001+
geojson=None,
1002+
locations=None,
1003+
color=None,
1004+
hover_name=None,
1005+
hover_data=None,
1006+
custom_data=None,
1007+
animation_frame=None,
1008+
animation_group=None,
1009+
category_orders={},
1010+
labels={},
1011+
color_continuous_scale=None,
1012+
range_color=None,
1013+
color_continuous_midpoint=None,
1014+
opacity=None,
1015+
zoom=None,
1016+
title=None,
1017+
template=None,
1018+
width=None,
1019+
height=None,
1020+
):
1021+
"""
1022+
In a Mapbox choropleth map, each row of `data_frame` is represented by a
1023+
colored region on a Mapbox map.
1024+
"""
1025+
return make_figure(
1026+
args=locals(),
1027+
constructor=go.Choroplethmapbox,
1028+
trace_patch=dict(geojson=geojson),
1029+
)
1030+
1031+
1032+
choropleth_mapbox.__doc__ = make_docstring(choropleth_mapbox)
1033+
1034+
10011035
def line_mapbox(
10021036
data_frame=None,
10031037
lat=None,

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ def make_trace_kwargs(args, trace_spec, g, mapping_labels, sizeref):
287287
v_label_col = get_decorated_label(args, col, None)
288288
mapping_labels[v_label_col] = "%%{customdata[%d]}" % (position)
289289
elif k == "color":
290-
if trace_spec.constructor == go.Choropleth:
290+
if trace_spec.constructor in [go.Choropleth, go.Choroplethmapbox]:
291291
result["z"] = g[v]
292292
result["coloraxis"] = "coloraxis1"
293293
mapping_labels[v_label] = "%{z}"
@@ -380,6 +380,7 @@ def configure_axes(args, constructor, fig, orders):
380380
go.Scatterpolargl: configure_polar_axes,
381381
go.Barpolar: configure_polar_axes,
382382
go.Scattermapbox: configure_mapbox,
383+
go.Choroplethmapbox: configure_mapbox,
383384
go.Scattergeo: configure_geo,
384385
go.Choropleth: configure_geo,
385386
}
@@ -569,7 +570,9 @@ def configure_mapbox(args, fig, orders):
569570
center=dict(
570571
lat=args["data_frame"][args["lat"]].mean(),
571572
lon=args["data_frame"][args["lon"]].mean(),
572-
),
573+
)
574+
if "lat" in args and "lon" in args
575+
else dict(),
573576
zoom=args["zoom"],
574577
)
575578
)
@@ -1221,6 +1224,7 @@ def make_figure(args, constructor, trace_patch={}, layout_patch={}):
12211224
go.Parcats,
12221225
go.Parcoords,
12231226
go.Choropleth,
1227+
go.Choroplethmapbox,
12241228
go.Histogram2d,
12251229
go.Sunburst,
12261230
go.Treemap,

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,10 @@
456456
],
457457
box=["boolean (default `False`)", "If `True`, boxes are drawn inside the violins."],
458458
notched=["boolean (default `False`)", "If `True`, boxes are drawn with notches."],
459+
geojson=[
460+
"GeoJSON-formatted dict",
461+
"Must contain a Polygon feature collection, with IDs, which are references from `locations`.",
462+
],
459463
cumulative=[
460464
"boolean (default `False`)",
461465
"If `True`, histogram values are cumulative.",

0 commit comments

Comments
 (0)