Skip to content
Closed
Changes from all commits
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
31 changes: 28 additions & 3 deletions packages/python/plotly/plotly/figure_factory/_dendrogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@ def create_dendrogram(
colorscale=None,
distfun=None,
linkagefun=lambda x: sch.linkage(x, "complete"),
truncate_mode=None,
hovertext=None,
color_threshold=None,
show_leaf_counts=None,
show_contracted=None,
leaf_rotation=None,
leaf_font_size=None
):
"""
Function that returns a dendrogram Plotly figure object. This is a thin
Expand Down Expand Up @@ -59,7 +64,7 @@ def create_dendrogram(
>>> fig.show()

Example 2: Dendrogram to put on the left of the heatmap

>>> from plotly.figure_factory import create_dendrogram

>>> import numpy as np
Expand All @@ -71,7 +76,7 @@ def create_dendrogram(
>>> dendro.show()

Example 3: Dendrogram with Pandas

>>> from plotly.figure_factory import create_dendrogram

>>> import numpy as np
Expand Down Expand Up @@ -104,6 +109,11 @@ def create_dendrogram(
linkagefun=linkagefun,
hovertext=hovertext,
color_threshold=color_threshold,
truncate_mode=truncate_mode,
show_leaf_counts=show_leaf_counts,
show_contracted=show_contracted,
leaf_rotation=leaf_rotation,
leaf_font_size=leaf_font_size
)

return graph_objs.Figure(data=dendrogram.data, layout=dendrogram.layout)
Expand All @@ -126,6 +136,11 @@ def __init__(
linkagefun=lambda x: sch.linkage(x, "complete"),
hovertext=None,
color_threshold=None,
truncate_mode=None,
show_leaf_counts=None,
show_contracted=None,
leaf_rotation=None,
leaf_font_size=None
):
self.orientation = orientation
self.labels = labels
Expand All @@ -135,6 +150,11 @@ def __init__(
self.leaves = []
self.sign = {self.xaxis: 1, self.yaxis: 1}
self.layout = {self.xaxis: {}, self.yaxis: {}}
self.truncate_mode = truncate_mode
self.show_leaf_counts= show_leaf_counts
self.show_contracted= show_contracted
self.leaf_rotation= leaf_rotation
self.leaf_font_size = leaf_font_size

if self.orientation in ["left", "bottom"]:
self.sign[self.xaxis] = 1
Expand Down Expand Up @@ -271,7 +291,7 @@ def set_axis_layout(self, axis_key):
"ticks": "outside",
"mirror": "allticks",
"rangemode": "tozero",
"showticklabels": True,
"showticklabels": False if self.truncate_mode != None else True,
"zeroline": False,
"showgrid": False,
"showline": True,
Expand Down Expand Up @@ -344,7 +364,12 @@ def get_dendrogram_traces(
orientation=self.orientation,
labels=self.labels,
no_plot=True,
truncate_mode=self.truncate_mode,
color_threshold=color_threshold,
show_leaf_counts=self.show_leaf_counts,
show_contracted=self.show_contracted,
leaf_rotation=self.leaf_rotation,
leaf_font_size=self.leaf_font_size
)

icoord = scp.array(P["icoord"])
Expand Down