Skip to content

Commit c2ca8ab

Browse files
committed
[Figure-Factory Dendrogram] Adding support for truncate_mode. Now the user can specify via an argument if they want this mode and they can also specify hovertext, color_threshold, show_leaf_counts, show_contracted, leaf_rotation, leaf_font_size. If the truncate mode is on, then showticklabels will be set to False, else, it will remain True
1 parent 1f19f5f commit c2ca8ab

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

packages/python/plotly/plotly/figure_factory/_dendrogram.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,13 @@ def create_dendrogram(
2121
colorscale=None,
2222
distfun=None,
2323
linkagefun=lambda x: sch.linkage(x, "complete"),
24+
truncate_mode=None,
2425
hovertext=None,
2526
color_threshold=None,
27+
show_leaf_counts=None,
28+
show_contracted=None,
29+
leaf_rotation=None,
30+
leaf_font_size=None
2631
):
2732
"""
2833
Function that returns a dendrogram Plotly figure object. This is a thin
@@ -59,7 +64,7 @@ def create_dendrogram(
5964
>>> fig.show()
6065
6166
Example 2: Dendrogram to put on the left of the heatmap
62-
67+
6368
>>> from plotly.figure_factory import create_dendrogram
6469
6570
>>> import numpy as np
@@ -71,7 +76,7 @@ def create_dendrogram(
7176
>>> dendro.show()
7277
7378
Example 3: Dendrogram with Pandas
74-
79+
7580
>>> from plotly.figure_factory import create_dendrogram
7681
7782
>>> import numpy as np
@@ -104,6 +109,11 @@ def create_dendrogram(
104109
linkagefun=linkagefun,
105110
hovertext=hovertext,
106111
color_threshold=color_threshold,
112+
truncate_mode=truncate_mode,
113+
show_leaf_counts=show_leaf_counts,
114+
show_contracted=show_contracted,
115+
leaf_rotation=leaf_rotation,
116+
leaf_font_size=leaf_font_size
107117
)
108118

109119
return graph_objs.Figure(data=dendrogram.data, layout=dendrogram.layout)
@@ -126,6 +136,11 @@ def __init__(
126136
linkagefun=lambda x: sch.linkage(x, "complete"),
127137
hovertext=None,
128138
color_threshold=None,
139+
truncate_mode=None,
140+
show_leaf_counts=None,
141+
show_contracted=None,
142+
leaf_rotation=None,
143+
leaf_font_size=None
129144
):
130145
self.orientation = orientation
131146
self.labels = labels
@@ -135,6 +150,11 @@ def __init__(
135150
self.leaves = []
136151
self.sign = {self.xaxis: 1, self.yaxis: 1}
137152
self.layout = {self.xaxis: {}, self.yaxis: {}}
153+
self.truncate_mode = truncate_mode
154+
self.show_leaf_counts= show_leaf_counts
155+
self.show_contracted= show_contracted
156+
self.leaf_rotation= leaf_rotation
157+
self.leaf_font_size = leaf_font_size
138158

139159
if self.orientation in ["left", "bottom"]:
140160
self.sign[self.xaxis] = 1
@@ -271,7 +291,7 @@ def set_axis_layout(self, axis_key):
271291
"ticks": "outside",
272292
"mirror": "allticks",
273293
"rangemode": "tozero",
274-
"showticklabels": True,
294+
"showticklabels": False if self.truncate_mode != None else True,
275295
"zeroline": False,
276296
"showgrid": False,
277297
"showline": True,
@@ -344,7 +364,12 @@ def get_dendrogram_traces(
344364
orientation=self.orientation,
345365
labels=self.labels,
346366
no_plot=True,
367+
truncate_mode=self.truncate_mode,
347368
color_threshold=color_threshold,
369+
show_leaf_counts=self.show_leaf_counts,
370+
show_contracted=self.show_contracted,
371+
leaf_rotation=self.leaf_rotation,
372+
leaf_font_size=self.leaf_font_size
348373
)
349374

350375
icoord = scp.array(P["icoord"])

0 commit comments

Comments
 (0)