Skip to content

Commit 947e7c2

Browse files
committed
minor improvements
1 parent b9f9084 commit 947e7c2

File tree

3 files changed

+51
-21
lines changed

3 files changed

+51
-21
lines changed

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

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,27 +1252,45 @@ def funnel(
12521252
x=None,
12531253
y=None,
12541254
color=None,
1255-
color_discrete_sequence=None,
1256-
color_discrete_map={},
1257-
orientation=None,
1258-
textinfo=None,
1255+
facet_row=None,
1256+
facet_col=None,
1257+
facet_col_wrap=0,
12591258
hover_name=None,
12601259
hover_data=None,
12611260
custom_data=None,
1261+
text=None,
1262+
error_x=None,
1263+
error_x_minus=None,
1264+
error_y=None,
1265+
error_y_minus=None,
1266+
animation_frame=None,
1267+
animation_group=None,
1268+
category_orders={},
12621269
labels={},
1270+
color_discrete_sequence=None,
1271+
color_discrete_map={},
1272+
color_continuous_scale=None,
1273+
range_color=None,
1274+
color_continuous_midpoint=None,
1275+
opacity=None,
1276+
orientation="h",
1277+
barmode="relative",
1278+
log_x=False,
1279+
log_y=False,
1280+
range_x=None,
1281+
range_y=None,
12631282
title=None,
12641283
template=None,
12651284
width=None,
12661285
height=None,
1267-
opacity=None,
12681286
):
12691287
"""
12701288
In a funnel plot, each row of `data_frame` is represented as a rectangular sector of a funnel.
12711289
"""
12721290
return make_figure(
12731291
args=locals(),
12741292
constructor=go.Funnel,
1275-
trace_patch=dict(opacity=opacity, orientation=orientation, textinfo=textinfo),
1293+
trace_patch=dict(opacity=opacity, orientation=orientation),
12761294
)
12771295

12781296

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

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -734,15 +734,6 @@ def one_group(x):
734734

735735
def apply_default_cascade(args):
736736
# first we apply px.defaults to unspecified args
737-
# If a discrete or a continuous colorscale is given then we do not set the other type
738-
# This is used for Sunburst and Treemap which accept the two
739-
# if ("color_discrete_sequence" in args and "color_continuous_scale" in args):
740-
# if args["color_discrete_sequence"] is None and args["color_continuous_scale"] is None:
741-
# for param in ["color_discrete_sequence", "color_continuous_scale"]:
742-
# args[param] = getattr(defaults, param)
743-
# else:
744-
# if param in args and args[param] is None:
745-
# args[param] = getattr(defaults, param)
746737

747738
for param in (
748739
["color_discrete_sequence", "color_continuous_scale"]
@@ -769,8 +760,6 @@ def apply_default_cascade(args):
769760
# if colors not set explicitly or in px.defaults, defer to a template
770761
# if the template doesn't have one, we set some final fallback defaults
771762
if "color_continuous_scale" in args:
772-
if args["color_continuous_scale"] is not None:
773-
args["color_is_continuous"] = True
774763
if (
775764
args["color_continuous_scale"] is None
776765
and args["template"].layout.colorscale.sequential
@@ -782,8 +771,6 @@ def apply_default_cascade(args):
782771
args["color_continuous_scale"] = sequential.Viridis
783772

784773
if "color_discrete_sequence" in args:
785-
if args["color_discrete_sequence"] is not None:
786-
args["color_is_continuous"] = False
787774
if args["color_discrete_sequence"] is None and args["template"].layout.colorway:
788775
args["color_discrete_sequence"] = args["template"].layout.colorway
789776
if args["color_discrete_sequence"] is None:
@@ -1064,10 +1051,10 @@ def infer_config(args, constructor, trace_patch):
10641051
and args["data_frame"][args["color"]].dtype.kind in "bifc"
10651052
):
10661053
attrs.append("color")
1067-
if not "color_is_continuous" in args:
1068-
args["color_is_continuous"] = True
1054+
args["color_is_continuous"] = True
10691055
elif constructor in [go.Sunburst, go.Treemap]:
10701056
attrs.append("color")
1057+
args["color_is_continuous"] = False
10711058
else:
10721059
if constructor not in [go.Pie, go.Funnelarea]:
10731060
grouped_attrs.append("marker.color")

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,20 @@ def test_sunburst_treemap_colorscales():
8686
el[0] == px.colors.sequential.Viridis
8787
for i, el in enumerate(fig.layout.coloraxis.colorscale)
8888
]
89+
# Numerical color arg passed, continuous colorscale
90+
# even if color_discrete_sequence if passed
91+
fig = func(
92+
names=labels,
93+
parents=parents,
94+
values=values,
95+
color=values,
96+
color_discrete_sequence=color_seq,
97+
)
98+
assert [
99+
el[0] == px.colors.sequential.Viridis
100+
for i, el in enumerate(fig.layout.coloraxis.colorscale)
101+
]
102+
89103
# Discrete colorscale, no color arg passed
90104
color_seq = px.colors.sequential.Reds
91105
fig = func(
@@ -116,3 +130,14 @@ def test_pie_funnelarea_colorscale():
116130
color_discrete_sequence=color_seq,
117131
)
118132
assert np.all([col in color_seq for col in fig.data[0].marker.colors])
133+
134+
135+
def test_funnel():
136+
fig = px.funnel(x=[5, 4, 3], y=["A", "B", "C"])
137+
assert fig.data[0].marker.color == "#636efa"
138+
fig = px.funnel(
139+
x=[5, 4, 3, 3, 2, 1],
140+
y=["A", "B", "C", "A", "B", "C"],
141+
color=["0", "0", "0", "1", "1", "1"],
142+
)
143+
assert len(fig.data) == 2

0 commit comments

Comments
 (0)