Skip to content

Commit 9d6360a

Browse files
tweaks to pie/funnel
1 parent ea87847 commit 9d6360a

File tree

2 files changed

+29
-62
lines changed

2 files changed

+29
-62
lines changed

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

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,7 +1124,6 @@ def pie(
11241124
color=None,
11251125
color_discrete_sequence=None,
11261126
color_discrete_map={},
1127-
textinfo=None,
11281127
hover_name=None,
11291128
hover_data=None,
11301129
custom_data=None,
@@ -1146,15 +1145,14 @@ def pie(
11461145
return make_figure(
11471146
args=locals(),
11481147
constructor=go.Pie,
1149-
trace_patch=dict(showlegend=True, hole=hole),
1148+
trace_patch=dict(showlegend=(names is not None), hole=hole),
11501149
layout_patch=layout_patch,
11511150
)
11521151

11531152

11541153
pie.__doc__ = make_docstring(
11551154
pie,
11561155
override_dict=dict(
1157-
textinfo=["str", "Determines which trace information appear on the graph.",],
11581156
hole=[
11591157
"float",
11601158
"Sets the fraction of the radius to cut out of the pie."
@@ -1230,7 +1228,7 @@ def treemap(
12301228
maxdepth=None,
12311229
):
12321230
"""
1233-
A treemap plot represents hierarchial data as nested rectangular sectors.
1231+
A treemap plot represents hierarchial data as nested rectangular sectors.
12341232
"""
12351233
if color_discrete_sequence is not None:
12361234
layout_patch = {"treemapcolorway": color_discrete_sequence}
@@ -1259,22 +1257,14 @@ def funnel(
12591257
hover_data=None,
12601258
custom_data=None,
12611259
text=None,
1262-
error_x=None,
1263-
error_x_minus=None,
1264-
error_y=None,
1265-
error_y_minus=None,
12661260
animation_frame=None,
12671261
animation_group=None,
12681262
category_orders={},
12691263
labels={},
12701264
color_discrete_sequence=None,
12711265
color_discrete_map={},
1272-
color_continuous_scale=None,
1273-
range_color=None,
1274-
color_continuous_midpoint=None,
12751266
opacity=None,
12761267
orientation="h",
1277-
barmode="relative",
12781268
log_x=False,
12791269
log_y=False,
12801270
range_x=None,
@@ -1294,15 +1284,7 @@ def funnel(
12941284
)
12951285

12961286

1297-
funnel.__doc__ = make_docstring(
1298-
funnel,
1299-
override_dict=dict(
1300-
textinfo=[
1301-
"str",
1302-
"Determines which trace information appear on the graph. In the case of having multiple funnels, percentages & totals are computed separately (per trace).",
1303-
]
1304-
),
1305-
)
1287+
funnel.__doc__ = make_docstring(funnel)
13061288

13071289

13081290
def funnel_area(
@@ -1312,7 +1294,6 @@ def funnel_area(
13121294
color=None,
13131295
color_discrete_sequence=None,
13141296
color_discrete_map={},
1315-
textinfo=None,
13161297
hover_name=None,
13171298
hover_data=None,
13181299
custom_data=None,
@@ -1333,17 +1314,10 @@ def funnel_area(
13331314
return make_figure(
13341315
args=locals(),
13351316
constructor=go.Funnelarea,
1336-
trace_patch=dict(showlegend=True),
1317+
trace_patch=dict(showlegend=(names is not None)),
13371318
layout_patch=layout_patch,
13381319
)
13391320

13401321

1341-
funnel_area.__doc__ = make_docstring(
1342-
funnel_area,
1343-
override_dict=dict(
1344-
textinfo=[
1345-
"str",
1346-
"Determines which trace information appear on the graph. In the case of having multiple funnels, percentages & totals are computed separately (per trace).",
1347-
]
1348-
),
1349-
)
1322+
funnel_area.__doc__ = make_docstring(funnel_area)
1323+

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

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,6 @@ def get_trendline_results(fig):
5959
return fig._px_trendlines
6060

6161

62-
def make_color_mapping(cat_list, discrete_colorscale):
63-
mapping = {}
64-
colors = []
65-
taken = 0
66-
length = len(discrete_colorscale)
67-
for cat in cat_list:
68-
if mapping.get(cat) is None:
69-
mapping[cat] = discrete_colorscale[taken % length]
70-
taken += 1
71-
colors.append(mapping[cat])
72-
return colors
73-
74-
7562
Mapping = namedtuple(
7663
"Mapping",
7764
[
@@ -304,26 +291,28 @@ def make_trace_kwargs(args, trace_spec, g, mapping_labels, sizeref):
304291
result["z"] = g[v]
305292
result["coloraxis"] = "coloraxis1"
306293
mapping_labels[v_label] = "%{z}"
307-
elif trace_spec.constructor in [go.Sunburst, go.Treemap]:
308-
colorable = "marker"
309-
if colorable not in result:
310-
result[colorable] = dict()
311-
# Other if/else block
294+
elif trace_spec.constructor in [
295+
go.Sunburst,
296+
go.Treemap,
297+
go.Pie,
298+
go.Funnelarea,
299+
]:
300+
if "marker" not in result:
301+
result["marker"] = dict()
302+
312303
if args.get("color_is_continuous"):
313-
result[colorable]["colors"] = g[v]
314-
result[colorable]["coloraxis"] = "coloraxis1"
304+
result["marker"]["colors"] = g[v]
305+
result["marker"]["coloraxis"] = "coloraxis1"
315306
mapping_labels[v_label] = "%{color}"
316307
else:
317-
result[colorable]["colors"] = make_color_mapping(
318-
g[v], args["color_discrete_sequence"]
319-
)
320-
elif trace_spec.constructor in [go.Pie, go.Funnelarea]:
321-
colorable = "marker"
322-
if colorable not in result:
323-
result[colorable] = dict()
324-
result[colorable]["colors"] = make_color_mapping(
325-
g[v], args["color_discrete_sequence"]
326-
)
308+
result["marker"]["colors"] = []
309+
mapping = {}
310+
for cat in g[v]:
311+
if mapping.get(cat) is None:
312+
mapping[cat] = args["color_discrete_sequence"][
313+
len(mapping) % len(args["color_discrete_sequence"])
314+
]
315+
result["marker"]["colors"].append(mapping[cat])
327316
else:
328317
colorable = "marker"
329318
if trace_spec.constructor in [go.Parcats, go.Parcoords]:
@@ -1064,6 +1053,10 @@ def infer_config(args, constructor, trace_patch):
10641053
grouped_attrs.append("marker.color")
10651054
else:
10661055
attrs.append("color")
1056+
if constructor in [go.Pie, go.Funnelarea]:
1057+
if args["hover_data"] is None:
1058+
args["hover_data"] = []
1059+
args["hover_data"].append(args["color"])
10671060

10681061
show_colorbar = bool(
10691062
"color" in attrs

0 commit comments

Comments
 (0)