Skip to content

Add option to set dendrogram color threshold #1214

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 1 commit into from
Oct 15, 2018
Merged
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
20 changes: 11 additions & 9 deletions plotly/figure_factory/_dendrogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
def create_dendrogram(X, orientation="bottom", labels=None,
colorscale=None, distfun=None,
linkagefun=lambda x: sch.linkage(x, 'complete'),
hovertext=None):
hovertext=None, color_threshold=None):
"""
BETA function that returns a dendrogram Plotly figure object.

Expand All @@ -28,10 +28,10 @@ def create_dendrogram(X, orientation="bottom", labels=None,
:param (function) distfun: Function to compute the pairwise distance from
the observations
:param (function) linkagefun: Function to compute the linkage matrix from
the pairwise distances
the pairwise distances
:param (list[list]) hovertext: List of hovertext for constituent traces of dendrogram

clusters
clusters
:param (double) color_threshold: Value at which the separation of clusters will be made

Example 1: Simple bottom oriented dendrogram
```
Expand Down Expand Up @@ -88,7 +88,7 @@ def create_dendrogram(X, orientation="bottom", labels=None,

dendrogram = _Dendrogram(X, orientation, labels, colorscale,
distfun=distfun, linkagefun=linkagefun,
hovertext=hovertext)
hovertext=hovertext, color_threshold=color_threshold)

return graph_objs.Figure(data=dendrogram.data,
layout=dendrogram.layout)
Expand All @@ -101,7 +101,7 @@ def __init__(self, X, orientation='bottom', labels=None, colorscale=None,
width=np.inf, height=np.inf, xaxis='xaxis', yaxis='yaxis',
distfun=None,
linkagefun=lambda x: sch.linkage(x, 'complete'),
hovertext=None):
hovertext=None, color_threshold=None):
self.orientation = orientation
self.labels = labels
self.xaxis = xaxis
Expand All @@ -128,7 +128,8 @@ def __init__(self, X, orientation='bottom', labels=None, colorscale=None,
ordered_labels, leaves) = self.get_dendrogram_traces(X, colorscale,
distfun,
linkagefun,
hovertext)
hovertext,
color_threshold)

self.labels = ordered_labels
self.leaves = leaves
Expand Down Expand Up @@ -249,7 +250,7 @@ def set_figure_layout(self, width, height):

return self.layout

def get_dendrogram_traces(self, X, colorscale, distfun, linkagefun, hovertext):
def get_dendrogram_traces(self, X, colorscale, distfun, linkagefun, hovertext, color_threshold):
"""
Calculates all the elements needed for plotting a dendrogram.

Expand All @@ -274,7 +275,8 @@ def get_dendrogram_traces(self, X, colorscale, distfun, linkagefun, hovertext):
d = distfun(X)
Z = linkagefun(d)
P = sch.dendrogram(Z, orientation=self.orientation,
labels=self.labels, no_plot=True)
labels=self.labels, no_plot=True,
color_threshold=color_threshold)

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