-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Added parameter to choose color_threshold #1075
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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='default'): | ||
""" | ||
BETA function that returns a dendrogram Plotly figure object. | ||
|
||
|
@@ -30,6 +30,7 @@ def create_dendrogram(X, orientation="bottom", labels=None, | |
:param (function) linkagefun: Function to compute the linkage matrix from | ||
the pairwise distances | ||
:param (list[list]) hovertext: List of hovertext for constituent traces of dendrogram | ||
:param (double) color_threshold: Value at which the separation of clusters will be made | ||
|
||
clusters | ||
|
||
|
@@ -88,20 +89,19 @@ 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) | ||
return graph_objs.Figure(data=dendrogram.data, layout=dendrogram.layout) | ||
|
||
|
||
class _Dendrogram(object): | ||
"""Refer to FigureFactory.create_dendrogram() for docstring.""" | ||
|
||
def __init__(self, X, orientation='bottom', labels=None, colorscale=None, | ||
width=np.inf, height=np.inf, xaxis='xaxis', yaxis='yaxis', | ||
width="100%", height="100%", xaxis='xaxis', yaxis='yaxis', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "100%" is not a valid height/width and it looks like this is causing your test failure. Where you trying to change some behavior here? I'm not sure why the old value was There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "100%" isn't a valid for a width/height. This is what's causing your test failure. I think this should probably be |
||
distfun=None, | ||
linkagefun=lambda x: sch.linkage(x, 'complete'), | ||
hovertext=None): | ||
hovertext=None, color_threshold='default'): | ||
self.orientation = orientation | ||
self.labels = labels | ||
self.xaxis = xaxis | ||
|
@@ -127,8 +127,9 @@ def __init__(self, X, orientation='bottom', labels=None, colorscale=None, | |
(dd_traces, xvals, yvals, | ||
ordered_labels, leaves) = self.get_dendrogram_traces(X, colorscale, | ||
distfun, | ||
linkagefun, | ||
hovertext) | ||
linkagefun, | ||
hovertext, | ||
color_threshold) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is there no closing parenthesis here? |
||
|
||
self.labels = ordered_labels | ||
self.leaves = leaves | ||
|
@@ -144,7 +145,7 @@ def __init__(self, X, orientation='bottom', labels=None, colorscale=None, | |
self.zero_vals.sort() | ||
|
||
self.layout = self.set_figure_layout(width, height) | ||
self.data = dd_traces | ||
self.data = graph_objs.Data(dd_traces) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
def get_color_dict(self, colorscale): | ||
""" | ||
|
@@ -237,7 +238,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. | ||
|
||
|
@@ -262,7 +263,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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please align with |
||
|
||
icoord = scp.array(P['icoord']) | ||
dcoord = scp.array(P['dcoord']) | ||
|
@@ -288,12 +290,11 @@ def get_dendrogram_traces(self, X, colorscale, distfun, linkagefun, hovertext): | |
hovertext_label = None | ||
if hovertext: | ||
hovertext_label = hovertext[i] | ||
trace = dict( | ||
type='scatter', | ||
trace = graph_objs.Scatter( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's stick with |
||
x=np.multiply(self.sign[self.xaxis], xs), | ||
y=np.multiply(self.sign[self.yaxis], ys), | ||
mode='lines', | ||
marker=dict(color=colors[color_key]), | ||
marker=graph_objs.Marker(color=colors[color_key]), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Stick with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
text=hovertext_label, | ||
hoverinfo='text' | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please align with
:param
above