Skip to content

Commit 78ed0f2

Browse files
committed
labels and names
1 parent 668eb90 commit 78ed0f2

File tree

4 files changed

+77
-13
lines changed

4 files changed

+77
-13
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
density_heatmap,
4242
pie,
4343
sunburst,
44+
treemap,
4445
funnel,
4546
funnel_area,
4647
)
@@ -83,7 +84,10 @@
8384
"choropleth",
8485
"pie",
8586
"sunburst",
86-
"funnel" "funnel_area" "imshow",
87+
"treemap",
88+
"funnel",
89+
"funnel_area",
90+
"imshow",
8791
"data",
8892
"colors",
8993
"set_mapbox_access_token",

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

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,8 +1119,9 @@ def parallel_categories(
11191119

11201120
def pie(
11211121
data_frame=None,
1122-
text=None,
1122+
names=None,
11231123
values=None,
1124+
textinfo=None,
11241125
hover_name=None,
11251126
hover_data=None,
11261127
custom_data=None,
@@ -1130,19 +1131,35 @@ def pie(
11301131
width=None,
11311132
height=None,
11321133
opacity=None,
1134+
hole=None,
11331135
):
11341136
"""
11351137
In a pie plot, each row of `data_frame` is represented as a sector of a pie.
11361138
"""
1137-
return make_figure(args=locals(), constructor=go.Pie,)
1139+
return make_figure(
1140+
args=locals(),
1141+
constructor=go.Pie,
1142+
trace_patch=dict(showlegend=True, hole=hole)
1143+
)
11381144

11391145

1140-
pie.__doc__ = make_docstring(pie)
1146+
pie.__doc__ = make_docstring(pie,
1147+
override_dict=dict(
1148+
textinfo=[
1149+
"str",
1150+
"Determines which trace information appear on the graph.",
1151+
],
1152+
hole=[
1153+
"float",
1154+
"Sets the fraction of the radius to cut out of the pie."
1155+
"Use this to make a donut chart."
1156+
],
1157+
),)
11411158

11421159

11431160
def sunburst(
11441161
data_frame=None,
1145-
text=None,
1162+
names=None,
11461163
values=None,
11471164
parents=None,
11481165
ids=None,
@@ -1158,7 +1175,8 @@ def sunburst(
11581175
maxdepth=None,
11591176
):
11601177
"""
1161-
In a pie plot, each row of `data_frame` is represented as a sector of a pie.
1178+
A sunburst plot represents hierarchial data as sectors laid out over
1179+
several levels of concentric rings.
11621180
"""
11631181
return make_figure(
11641182
args=locals(),
@@ -1170,6 +1188,36 @@ def sunburst(
11701188
sunburst.__doc__ = make_docstring(sunburst)
11711189

11721190

1191+
def treemap(
1192+
data_frame=None,
1193+
names=None,
1194+
values=None,
1195+
parents=None,
1196+
ids=None,
1197+
hover_name=None,
1198+
hover_data=None,
1199+
custom_data=None,
1200+
labels={},
1201+
title=None,
1202+
template=None,
1203+
width=None,
1204+
height=None,
1205+
branchvalues=None,
1206+
maxdepth=None,
1207+
):
1208+
"""
1209+
A treemap plot represents hierarchial data as nested rectangular sectors.
1210+
"""
1211+
return make_figure(
1212+
args=locals(),
1213+
constructor=go.Treemap,
1214+
trace_patch=dict(branchvalues=branchvalues, maxdepth=maxdepth),
1215+
)
1216+
1217+
1218+
treemap.__doc__ = make_docstring(treemap)
1219+
1220+
11731221
def funnel(
11741222
data_frame=None,
11751223
x=None,
@@ -1213,7 +1261,7 @@ def funnel(
12131261
def funnel_area(
12141262
data_frame=None,
12151263
values=None,
1216-
text=None,
1264+
names=None,
12171265
textinfo=None,
12181266
hover_name=None,
12191267
hover_data=None,

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -307,16 +307,21 @@ def make_trace_kwargs(args, trace_spec, g, mapping_labels, sizeref):
307307
mapping_labels[v_label] = "%{location}"
308308
elif k == "values":
309309
result[k] = g[v]
310-
mapping_labels["value"] = "%{value}"
310+
_label = "value" if v_label == 'values' else v_label
311+
mapping_labels[_label] = "%{value}"
311312
elif k == "parents":
312313
result[k] = g[v]
313-
mapping_labels["parent"] = "%{parent}"
314+
_label = "parent" if v_label == 'parents' else v_label
315+
mapping_labels[_label] = "%{parent}"
314316
elif k == "ids":
315317
result[k] = g[v]
316-
mapping_labels["id"] = "%{id}"
317-
elif k == "text":
318-
if trace_spec.constructor in [go.Sunburst, go.Treemap]:
318+
_label = "id" if v_label == 'ids' else v_label
319+
mapping_labels[_label] = "%{id}"
320+
elif k == "names":
321+
if trace_spec.constructor in [go.Sunburst, go.Treemap, go.Pie, go.Funnelarea]:
319322
result["labels"] = g[v]
323+
_label = "label" if v_label == 'names' else v_label
324+
mapping_labels[_label] = "%{label}"
320325
else:
321326
result[k] = g[v]
322327
else:
@@ -975,7 +980,7 @@ def infer_config(args, constructor, trace_patch):
975980
attrables = (
976981
["x", "y", "z", "a", "b", "c", "r", "theta", "size", "dimensions"]
977982
+ ["custom_data", "hover_name", "hover_data", "text"]
978-
+ ["values", "parents", "ids"]
983+
+ ["names", "values", "parents", "ids"]
979984
+ ["error_x", "error_x_minus"]
980985
+ ["error_y", "error_y_minus", "error_z", "error_z_minus"]
981986
+ ["lat", "lon", "locations", "animation_group"]
@@ -1171,6 +1176,7 @@ def make_figure(args, constructor, trace_patch={}, layout_patch={}):
11711176
go.Choropleth,
11721177
go.Histogram2d,
11731178
go.Sunburst,
1179+
go.Treemap,
11741180
]:
11751181
trace.update(
11761182
legendgroup=trace_name,

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,12 @@
183183
colref_desc,
184184
"Values from this column or array_like appear in the figure as text labels.",
185185
],
186+
names=[
187+
colref_type,
188+
colref_desc,
189+
"Values from this column or array_like are used as labels for sectors.",
190+
],
191+
186192
locationmode=[
187193
"str",
188194
"One of 'ISO-3', 'USA-states', or 'country names'",

0 commit comments

Comments
 (0)