Skip to content

Icicle cherrypick #3256

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 18, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add(icicle px): reveal icicle in plotly express
  • Loading branch information
Coding-with-Adam authored and nicolaskruchten committed Jun 18, 2021
commit e7267bcbce1425c94da28773c69f5835636ad20c
2 changes: 2 additions & 0 deletions packages/python/plotly/plotly/express/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
pie,
sunburst,
treemap,
icicle,
funnel,
funnel_area,
choropleth_mapbox,
Expand Down Expand Up @@ -93,6 +94,7 @@
"pie",
"sunburst",
"treemap",
"icicle",
"funnel",
"funnel_area",
"imshow",
Expand Down
64 changes: 61 additions & 3 deletions packages/python/plotly/plotly/express/_chart_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,9 @@ def density_heatmap(
z=[
"For `density_heatmap` and `density_contour` these values are used as the inputs to `histfunc`.",
],
histfunc=["The arguments to this function are the values of `z`.",],
histfunc=[
"The arguments to this function are the values of `z`.",
],
),
)

Expand Down Expand Up @@ -451,7 +453,9 @@ def histogram(
args=locals(),
constructor=go.Histogram,
trace_patch=dict(
histnorm=histnorm, histfunc=histfunc, cumulative=dict(enabled=cumulative),
histnorm=histnorm,
histfunc=histfunc,
cumulative=dict(enabled=cumulative),
),
layout_patch=dict(barmode=barmode, barnorm=barnorm),
)
Expand Down Expand Up @@ -511,7 +515,11 @@ def violin(
args=locals(),
constructor=go.Violin,
trace_patch=dict(
points=points, box=dict(visible=box), scalegroup=True, x0=" ", y0=" ",
points=points,
box=dict(visible=box),
scalegroup=True,
x0=" ",
y0=" ",
),
layout_patch=dict(violinmode=violinmode),
)
Expand Down Expand Up @@ -1472,6 +1480,56 @@ def treemap(
treemap.__doc__ = make_docstring(treemap)


def icicle(
data_frame=None,
names=None,
values=None,
parents=None,
path=None,
ids=None,
color=None,
color_continuous_scale=None,
range_color=None,
color_continuous_midpoint=None,
color_discrete_sequence=None,
color_discrete_map=None,
hover_name=None,
hover_data=None,
custom_data=None,
labels=None,
title=None,
template=None,
width=None,
height=None,
branchvalues=None,
maxdepth=None,
):
"""
An icicle plot represents hierarchial data with adjoined rectangular
sectors that all cascade from root down to leaf in one direction.
"""
if color_discrete_sequence is not None:
layout_patch = {"iciclecolorway": color_discrete_sequence}
else:
layout_patch = {}
if path is not None and (ids is not None or parents is not None):
raise ValueError(
"Either `path` should be provided, or `ids` and `parents`."
"These parameters are mutually exclusive and cannot be passed together."
)
if path is not None and branchvalues is None:
branchvalues = "total"
return make_figure(
args=locals(),
constructor=go.Icicle,
trace_patch=dict(branchvalues=branchvalues, maxdepth=maxdepth),
layout_patch=layout_patch,
)


icicle.__doc__ = make_docstring(icicle)


def funnel(
data_frame=None,
x=None,
Expand Down
11 changes: 7 additions & 4 deletions packages/python/plotly/plotly/express/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ def make_trace_kwargs(args, trace_spec, trace_data, mapping_labels, sizeref):
elif trace_spec.constructor in [
go.Sunburst,
go.Treemap,
go.Icicle,
go.Pie,
go.Funnelarea,
]:
Expand Down Expand Up @@ -480,6 +481,7 @@ def make_trace_kwargs(args, trace_spec, trace_data, mapping_labels, sizeref):
if trace_spec.constructor in [
go.Sunburst,
go.Treemap,
go.Icicle,
go.Pie,
go.Funnelarea,
]:
Expand Down Expand Up @@ -1497,7 +1499,7 @@ def _check_dataframe_all_leaves(df):

def process_dataframe_hierarchy(args):
"""
Build dataframe for sunburst or treemap when the path argument is provided.
Build dataframe for sunburst, treemap, or icicle when the path argument is provided.
"""
df = args["data_frame"]
path = args["path"][::-1]
Expand Down Expand Up @@ -1663,7 +1665,7 @@ def infer_config(args, constructor, trace_patch, layout_patch):
if args["color"] and _is_continuous(args["data_frame"], args["color"]):
attrs.append("color")
args["color_is_continuous"] = True
elif constructor in [go.Sunburst, go.Treemap]:
elif constructor in [go.Sunburst, go.Treemap, go.Icicle]:
attrs.append("color")
args["color_is_continuous"] = False
else:
Expand All @@ -1684,7 +1686,7 @@ def infer_config(args, constructor, trace_patch, layout_patch):
and args["color"]
and constructor not in [go.Pie, go.Funnelarea]
and (
constructor not in [go.Treemap, go.Sunburst]
constructor not in [go.Treemap, go.Sunburst, go.Icicle]
or args.get("color_is_continuous")
)
)
Expand Down Expand Up @@ -1856,7 +1858,7 @@ def make_figure(args, constructor, trace_patch=None, layout_patch=None):
apply_default_cascade(args)

args = build_dataframe(args, constructor)
if constructor in [go.Treemap, go.Sunburst] and args["path"] is not None:
if constructor in [go.Treemap, go.Sunburst, go.Icicle] and args["path"] is not None:
args = process_dataframe_hierarchy(args)
if constructor == "timeline":
constructor = go.Bar
Expand Down Expand Up @@ -1928,6 +1930,7 @@ def make_figure(args, constructor, trace_patch=None, layout_patch=None):
go.Histogram2d,
go.Sunburst,
go.Treemap,
go.Icicle,
]:
trace.update(
legendgroup=trace_name,
Expand Down