Skip to content

Commit 32ba543

Browse files
committed
Improve plotting coverage
1 parent 4243ef1 commit 32ba543

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

hdbscan/plots.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ def __init__(self, mst, data):
649649

650650
def plot(self, axis=None, node_size=40, node_color='k',
651651
node_alpha=0.8, edge_alpha=0.5, edge_cmap='viridis_r',
652-
edge_linewidth=2, vary_linewidth=True, colorbar=True):
652+
edge_linewidth=2, vary_line_width=True, colorbar=True):
653653
"""Plot the minimum spanning tree (as projected into 2D by t-SNE if required).
654654
655655
Parameters
@@ -680,7 +680,7 @@ def plot(self, axis=None, node_size=40, node_color='k',
680680
edge_linewidth : float, optional
681681
The linewidth to use for rendering edges (default 2).
682682
683-
vary_linewidth : bool, optional
683+
vary_line_width : bool, optional
684684
Edge width is proportional to (log of) the inverse of the
685685
mutual reachability distance. (default True)
686686
@@ -718,7 +718,7 @@ def plot(self, axis=None, node_size=40, node_color='k',
718718
else:
719719
projection = self._data.copy()
720720

721-
if vary_linewidth:
721+
if vary_line_width:
722722
line_width = edge_linewidth * (np.log(self._mst.T[2].max() / self._mst.T[2]) + 1.0)
723723
else:
724724
line_width = edge_linewidth

hdbscan/tests/test_hdbscan.py

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,37 @@ def test_hdbscan_boruvka_balltree_matches():
271271
assert_less(num_mismatches / float(data.shape[0]), 0.15)
272272

273273
def test_condensed_tree_plot():
274-
clusterer = HDBSCAN().fit(X)
275-
clusterer.condensed_tree_.get_plot_data()
276-
if_matplotlib(clusterer.condensed_tree_.plot)(select_clusters=True, selection_palette=('r','g','b'))
274+
clusterer = HDBSCAN(gen_min_span_tree=True).fit(X)
275+
if_matplotlib(clusterer.condensed_tree_.plot)(select_clusters=True,
276+
selection_palette=('r','g','b'),
277+
cmap='Reds')
278+
if_matplotlib(clusterer.condensed_tree_.plot)(label_clusters=True,
279+
colorbar=False,
280+
cmap='none')
281+
282+
def test_single_linkage_tree_plot():
283+
clusterer = HDBSCAN(gen_min_span_tree=True).fit(X)
284+
if_matplotlib(clusterer.single_linkage_tree_.plot)()
285+
if_matplotlib(clusterer.single_linkage_tree_.plot)(vary_line_width=False,
286+
truncate_mode='lastp',
287+
p=10,
288+
colorbar=False)
289+
290+
def test_min_span_tree_plot():
291+
clusterer = HDBSCAN(gen_min_span_tree=True).fit(X)
292+
if_matplotlib(clusterer.minimum_spanning_tree_.plot)()
293+
294+
H, y = make_blobs(n_samples=50, random_state=0, n_features=10)
295+
H = StandardScaler().fit_transform(H)
296+
297+
clusterer = HDBSCAN(gen_min_span_tree=True).fit(H)
298+
if_matplotlib(clusterer.minimum_spanning_tree_.plot)(vary_line_width=False, colorbar=False)
299+
300+
H, y = make_blobs(n_samples=50, random_state=0, n_features=40)
301+
H = StandardScaler().fit_transform(H)
302+
303+
clusterer = HDBSCAN(gen_min_span_tree=True).fit(H)
304+
if_matplotlib(clusterer.minimum_spanning_tree_.plot)(vary_line_width=False, colorbar=False)
277305

278306
def test_tree_numpy_output_formats():
279307

0 commit comments

Comments
 (0)