Skip to content

Commit d2cec8f

Browse files
px.density_mapbox
1 parent dd577a0 commit d2cec8f

File tree

4 files changed

+49
-6
lines changed

4 files changed

+49
-6
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"""
55
from __future__ import absolute_import
66
from plotly import optional_imports
7+
from ._imshow import imshow
78

89
pd = optional_imports.get_module("pandas")
910
if pd is None:
@@ -12,7 +13,6 @@
1213
Plotly express requires pandas to be installed."""
1314
)
1415

15-
1616
from ._chart_types import ( # noqa: F401
1717
scatter,
1818
scatter_3d,
@@ -45,9 +45,9 @@
4545
funnel,
4646
funnel_area,
4747
choropleth_mapbox,
48+
density_mapbox,
4849
)
4950

50-
from ._imshow import imshow
5151

5252
from ._core import ( # noqa: F401
5353
set_mapbox_access_token,
@@ -67,6 +67,7 @@
6767
"scatter_matrix",
6868
"density_contour",
6969
"density_heatmap",
70+
"density_mapbox",
7071
"line",
7172
"line_3d",
7273
"line_polar",

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,41 @@ def choropleth_mapbox(
10321032
choropleth_mapbox.__doc__ = make_docstring(choropleth_mapbox)
10331033

10341034

1035+
def density_mapbox(
1036+
data_frame=None,
1037+
lat=None,
1038+
lon=None,
1039+
z=None,
1040+
hover_name=None,
1041+
hover_data=None,
1042+
custom_data=None,
1043+
animation_frame=None,
1044+
animation_group=None,
1045+
category_orders={},
1046+
labels={},
1047+
color_continuous_scale=None,
1048+
range_color=None,
1049+
color_continuous_midpoint=None,
1050+
opacity=None,
1051+
zoom=8,
1052+
radius=None,
1053+
title=None,
1054+
template=None,
1055+
width=None,
1056+
height=None,
1057+
):
1058+
"""
1059+
In a Mapbox density map, each row of `data_frame` contributes to the intensity of
1060+
the color of the region around the corresponding point on the map
1061+
"""
1062+
return make_figure(
1063+
args=locals(), constructor=go.Densitymapbox, trace_patch=dict(radius=radius)
1064+
)
1065+
1066+
1067+
density_mapbox.__doc__ = make_docstring(density_mapbox)
1068+
1069+
10351070
def line_mapbox(
10361071
data_frame=None,
10371072
lat=None,

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ def configure_axes(args, constructor, fig, orders):
381381
go.Barpolar: configure_polar_axes,
382382
go.Scattermapbox: configure_mapbox,
383383
go.Choroplethmapbox: configure_mapbox,
384+
go.Densitymapbox: configure_mapbox,
384385
go.Scattergeo: configure_geo,
385386
go.Choropleth: configure_geo,
386387
}
@@ -571,7 +572,7 @@ def configure_mapbox(args, fig, orders):
571572
lat=args["data_frame"][args["lat"]].mean(),
572573
lon=args["data_frame"][args["lon"]].mean(),
573574
)
574-
if "lat" in args and "lon" in args
575+
if "lat" in args and "lon" in args
575576
else dict(),
576577
zoom=args["zoom"],
577578
)
@@ -1012,7 +1013,7 @@ def infer_config(args, constructor, trace_patch):
10121013
attrables = (
10131014
["x", "y", "z", "a", "b", "c", "r", "theta", "size", "dimensions"]
10141015
+ ["custom_data", "hover_name", "hover_data", "text"]
1015-
+ ["names", "values", "parents", "ids"]
1016+
+ ["names", "values", "parents", "ids", "radius"]
10161017
+ ["error_x", "error_x_minus"]
10171018
+ ["error_y", "error_y_minus", "error_z", "error_z_minus"]
10181019
+ ["lat", "lon", "locations", "animation_group"]
@@ -1086,7 +1087,7 @@ def infer_config(args, constructor, trace_patch):
10861087
# Compute final trace patch
10871088
trace_patch = trace_patch.copy()
10881089

1089-
if constructor == go.Histogram2d:
1090+
if constructor in [go.Histogram2d, go.Densitymapbox]:
10901091
show_colorbar = True
10911092
trace_patch["coloraxis"] = "coloraxis1"
10921093

@@ -1225,6 +1226,7 @@ def make_figure(args, constructor, trace_patch={}, layout_patch={}):
12251226
go.Parcoords,
12261227
go.Choropleth,
12271228
go.Choroplethmapbox,
1229+
go.Densitymapbox,
12281230
go.Histogram2d,
12291231
go.Sunburst,
12301232
go.Treemap,
@@ -1325,7 +1327,7 @@ def make_figure(args, constructor, trace_patch={}, layout_patch={}):
13251327
)
13261328
layout_patch = layout_patch.copy()
13271329
if show_colorbar:
1328-
colorvar = "z" if constructor == go.Histogram2d else "color"
1330+
colorvar = "z" if constructor in [go.Histogram2d, go.Densitymapbox] else "color"
13291331
range_color = args["range_color"] or [None, None]
13301332

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

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,11 @@
164164
colref_desc,
165165
"Values from this column or array_like are used to assign mark sizes.",
166166
],
167+
radius=[
168+
colref_type,
169+
colref_desc,
170+
"Values from this column or array_like are used to set the radius of influence of each point.",
171+
],
167172
hover_name=[
168173
colref_type,
169174
colref_desc,

0 commit comments

Comments
 (0)