Skip to content

Commit b9f9084

Browse files
committed
added funnelarea
1 parent e2902b4 commit b9f9084

File tree

3 files changed

+50
-20
lines changed

3 files changed

+50
-20
lines changed

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,6 +1141,8 @@ def pie(
11411141
"""
11421142
if color_discrete_sequence is not None:
11431143
layout_patch = {"piecolorway": color_discrete_sequence}
1144+
else:
1145+
layout_patch = {}
11441146
return make_figure(
11451147
args=locals(),
11461148
constructor=go.Pie,
@@ -1191,6 +1193,8 @@ def sunburst(
11911193
"""
11921194
if color_discrete_sequence is not None:
11931195
layout_patch = {"sunburstcolorway": color_discrete_sequence}
1196+
else:
1197+
layout_patch = {}
11941198
return make_figure(
11951199
args=locals(),
11961200
constructor=go.Sunburst,
@@ -1230,6 +1234,8 @@ def treemap(
12301234
"""
12311235
if color_discrete_sequence is not None:
12321236
layout_patch = {"treemapcolorway": color_discrete_sequence}
1237+
else:
1238+
layout_patch = {}
12331239
return make_figure(
12341240
args=locals(),
12351241
constructor=go.Treemap,
@@ -1283,8 +1289,11 @@ def funnel(
12831289

12841290
def funnel_area(
12851291
data_frame=None,
1286-
values=None,
12871292
names=None,
1293+
values=None,
1294+
color=None,
1295+
color_discrete_sequence=None,
1296+
color_discrete_map={},
12881297
textinfo=None,
12891298
hover_name=None,
12901299
hover_data=None,
@@ -1294,12 +1303,20 @@ def funnel_area(
12941303
template=None,
12951304
width=None,
12961305
height=None,
1306+
opacity=None,
12971307
):
12981308
"""
12991309
In a funnel area plot, each row of `data_frame` is represented as a trapezoidal sector of a funnel.
13001310
"""
1311+
if color_discrete_sequence is not None:
1312+
layout_patch = {"funnelareacolorway": color_discrete_sequence}
1313+
else:
1314+
layout_patch = {}
13011315
return make_figure(
1302-
args=locals(), constructor=go.Funnelarea, trace_patch=dict(showlegend=True)
1316+
args=locals(),
1317+
constructor=go.Funnelarea,
1318+
trace_patch=dict(showlegend=True),
1319+
layout_patch=layout_patch,
13031320
)
13041321

13051322

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

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -308,25 +308,16 @@ def make_trace_kwargs(args, trace_spec, g, mapping_labels, sizeref):
308308
colorable = "marker"
309309
if colorable not in result:
310310
result[colorable] = dict()
311-
print("ok")
311+
# Other if/else block
312312
if args.get("color_is_continuous"):
313-
print(
314-
"continuous scale", args["color_continuous_scale"],
315-
)
316313
result[colorable]["colors"] = g[v]
317-
result[colorable]["colorscale"] = args["color_continuous_scale"]
318-
# result[colorable]["coloraxis"] = "coloraxis1"
314+
result[colorable]["coloraxis"] = "coloraxis1"
319315
mapping_labels[v_label] = "%{color}"
320316
else:
321-
print(
322-
"discrete",
323-
args["color_discrete_sequence"],
324-
args.get("color_is_continuous"),
325-
)
326317
result[colorable]["colors"] = make_color_mapping(
327318
g[v], args["color_discrete_sequence"]
328319
)
329-
elif trace_spec.constructor == go.Pie:
320+
elif trace_spec.constructor in [go.Pie, go.Funnelarea]:
330321
colorable = "marker"
331322
if colorable not in result:
332323
result[colorable] = dict()
@@ -779,7 +770,6 @@ def apply_default_cascade(args):
779770
# if the template doesn't have one, we set some final fallback defaults
780771
if "color_continuous_scale" in args:
781772
if args["color_continuous_scale"] is not None:
782-
print("True in cascade")
783773
args["color_is_continuous"] = True
784774
if (
785775
args["color_continuous_scale"] is None
@@ -793,7 +783,6 @@ def apply_default_cascade(args):
793783

794784
if "color_discrete_sequence" in args:
795785
if args["color_discrete_sequence"] is not None:
796-
print("False in cascade")
797786
args["color_is_continuous"] = False
798787
if args["color_discrete_sequence"] is None and args["template"].layout.colorway:
799788
args["color_discrete_sequence"] = args["template"].layout.colorway
@@ -1076,24 +1065,27 @@ def infer_config(args, constructor, trace_patch):
10761065
):
10771066
attrs.append("color")
10781067
if not "color_is_continuous" in args:
1079-
print("True in infer 2")
10801068
args["color_is_continuous"] = True
10811069
elif constructor in [go.Sunburst, go.Treemap]:
10821070
attrs.append("color")
10831071
else:
1084-
if constructor not in [go.Pie]:
1072+
if constructor not in [go.Pie, go.Funnelarea]:
10851073
grouped_attrs.append("marker.color")
10861074
elif "line_group" in args or constructor == go.Histogram2dContour:
10871075
grouped_attrs.append("line.color")
1088-
elif constructor not in [go.Pie, go.Sunburst, go.Treemap]:
1076+
elif constructor not in [go.Pie, go.Funnelarea]:
10891077
grouped_attrs.append("marker.color")
10901078
else:
10911079
attrs.append("color")
10921080

10931081
show_colorbar = bool(
10941082
"color" in attrs
10951083
and args["color"]
1096-
and constructor not in [go.Pie, go.Sunburst, go.Treemap]
1084+
and constructor not in [go.Pie, go.Funnelarea]
1085+
and (
1086+
constructor not in [go.Treemap, go.Sunburst]
1087+
or args.get("color_is_continuous")
1088+
)
10971089
)
10981090
else:
10991091
show_colorbar = False

packages/python/plotly/plotly/tests/test_core/test_px/test_px_functions.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,24 @@ def test_sunburst_treemap_colorscales():
9595
color_discrete_sequence=color_seq,
9696
)
9797
assert list(fig.layout[colorway]) == color_seq
98+
99+
100+
def test_pie_funnelarea_colorscale():
101+
labels = ["A", "B", "C", "D"]
102+
values = [3, 2, 1, 4]
103+
for func, colorway in zip(
104+
[px.sunburst, px.treemap], ["sunburstcolorway", "treemapcolorway"]
105+
):
106+
# Discrete colorscale, no color arg passed
107+
color_seq = px.colors.sequential.Reds
108+
fig = func(names=labels, values=values, color_discrete_sequence=color_seq,)
109+
assert list(fig.layout[colorway]) == color_seq
110+
# Discrete colorscale, color arg passed
111+
color_seq = px.colors.sequential.Reds
112+
fig = func(
113+
names=labels,
114+
values=values,
115+
color=labels,
116+
color_discrete_sequence=color_seq,
117+
)
118+
assert np.all([col in color_seq for col in fig.data[0].marker.colors])

0 commit comments

Comments
 (0)