Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e7267bc

Browse files
Coding-with-Adamnicolaskruchten
authored andcommitted
add(icicle px): reveal icicle in plotly express
1 parent 45c29d9 commit e7267bc

File tree

3 files changed

+70
-7
lines changed

3 files changed

+70
-7
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
pie,
4444
sunburst,
4545
treemap,
46+
icicle,
4647
funnel,
4748
funnel_area,
4849
choropleth_mapbox,
@@ -93,6 +94,7 @@
9394
"pie",
9495
"sunburst",
9596
"treemap",
97+
"icicle",
9698
"funnel",
9799
"funnel_area",
98100
"imshow",

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

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,9 @@ def density_heatmap(
200200
z=[
201201
"For `density_heatmap` and `density_contour` these values are used as the inputs to `histfunc`.",
202202
],
203-
histfunc=["The arguments to this function are the values of `z`.",],
203+
histfunc=[
204+
"The arguments to this function are the values of `z`.",
205+
],
204206
),
205207
)
206208

@@ -451,7 +453,9 @@ def histogram(
451453
args=locals(),
452454
constructor=go.Histogram,
453455
trace_patch=dict(
454-
histnorm=histnorm, histfunc=histfunc, cumulative=dict(enabled=cumulative),
456+
histnorm=histnorm,
457+
histfunc=histfunc,
458+
cumulative=dict(enabled=cumulative),
455459
),
456460
layout_patch=dict(barmode=barmode, barnorm=barnorm),
457461
)
@@ -511,7 +515,11 @@ def violin(
511515
args=locals(),
512516
constructor=go.Violin,
513517
trace_patch=dict(
514-
points=points, box=dict(visible=box), scalegroup=True, x0=" ", y0=" ",
518+
points=points,
519+
box=dict(visible=box),
520+
scalegroup=True,
521+
x0=" ",
522+
y0=" ",
515523
),
516524
layout_patch=dict(violinmode=violinmode),
517525
)
@@ -1472,6 +1480,56 @@ def treemap(
14721480
treemap.__doc__ = make_docstring(treemap)
14731481

14741482

1483+
def icicle(
1484+
data_frame=None,
1485+
names=None,
1486+
values=None,
1487+
parents=None,
1488+
path=None,
1489+
ids=None,
1490+
color=None,
1491+
color_continuous_scale=None,
1492+
range_color=None,
1493+
color_continuous_midpoint=None,
1494+
color_discrete_sequence=None,
1495+
color_discrete_map=None,
1496+
hover_name=None,
1497+
hover_data=None,
1498+
custom_data=None,
1499+
labels=None,
1500+
title=None,
1501+
template=None,
1502+
width=None,
1503+
height=None,
1504+
branchvalues=None,
1505+
maxdepth=None,
1506+
):
1507+
"""
1508+
An icicle plot represents hierarchial data with adjoined rectangular
1509+
sectors that all cascade from root down to leaf in one direction.
1510+
"""
1511+
if color_discrete_sequence is not None:
1512+
layout_patch = {"iciclecolorway": color_discrete_sequence}
1513+
else:
1514+
layout_patch = {}
1515+
if path is not None and (ids is not None or parents is not None):
1516+
raise ValueError(
1517+
"Either `path` should be provided, or `ids` and `parents`."
1518+
"These parameters are mutually exclusive and cannot be passed together."
1519+
)
1520+
if path is not None and branchvalues is None:
1521+
branchvalues = "total"
1522+
return make_figure(
1523+
args=locals(),
1524+
constructor=go.Icicle,
1525+
trace_patch=dict(branchvalues=branchvalues, maxdepth=maxdepth),
1526+
layout_patch=layout_patch,
1527+
)
1528+
1529+
1530+
icicle.__doc__ = make_docstring(icicle)
1531+
1532+
14751533
def funnel(
14761534
data_frame=None,
14771535
x=None,

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ def make_trace_kwargs(args, trace_spec, trace_data, mapping_labels, sizeref):
428428
elif trace_spec.constructor in [
429429
go.Sunburst,
430430
go.Treemap,
431+
go.Icicle,
431432
go.Pie,
432433
go.Funnelarea,
433434
]:
@@ -480,6 +481,7 @@ def make_trace_kwargs(args, trace_spec, trace_data, mapping_labels, sizeref):
480481
if trace_spec.constructor in [
481482
go.Sunburst,
482483
go.Treemap,
484+
go.Icicle,
483485
go.Pie,
484486
go.Funnelarea,
485487
]:
@@ -1497,7 +1499,7 @@ def _check_dataframe_all_leaves(df):
14971499

14981500
def process_dataframe_hierarchy(args):
14991501
"""
1500-
Build dataframe for sunburstor treemap when the path argument is provided.
1502+
Build dataframe for sunburst, treemap, or icicle when the path argument is provided.
15011503
"""
15021504
df = args["data_frame"]
15031505
path = args["path"][::-1]
@@ -1663,7 +1665,7 @@ def infer_config(args, constructor, trace_patch, layout_patch):
16631665
if args["color"] and _is_continuous(args["data_frame"], args["color"]):
16641666
attrs.append("color")
16651667
args["color_is_continuous"] = True
1666-
elif constructor in [go.Sunburst, go.Treemap]:
1668+
elif constructor in [go.Sunburst, go.Treemap, go.Icicle]:
16671669
attrs.append("color")
16681670
args["color_is_continuous"] = False
16691671
else:
@@ -1684,7 +1686,7 @@ def infer_config(args, constructor, trace_patch, layout_patch):
16841686
and args["color"]
16851687
and constructor not in [go.Pie, go.Funnelarea]
16861688
and (
1687-
constructor not in [go.Treemap, go.Sunburst]
1689+
constructor not in [go.Treemap, go.Sunburst, go.Icicle]
16881690
or args.get("color_is_continuous")
16891691
)
16901692
)
@@ -1856,7 +1858,7 @@ def make_figure(args, constructor, trace_patch=None, layout_patch=None):
18561858
apply_default_cascade(args)
18571859

18581860
args = build_dataframe(args, constructor)
1859-
if constructor in [go.Treemap, go.Sunburst] and args["path"] is not None:
1861+
if constructor in [go.Treemap, go.Sunburst, go.Icicle] and args["path"] is not None:
18601862
args = process_dataframe_hierarchy(args)
18611863
if constructor == "timeline":
18621864
constructor = go.Bar
@@ -1928,6 +1930,7 @@ def make_figure(args, constructor, trace_patch=None, layout_patch=None):
19281930
go.Histogram2d,
19291931
go.Sunburst,
19301932
go.Treemap,
1933+
go.Icicle,
19311934
]:
19321935
trace.update(
19331936
legendgroup=trace_name,

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /