def check_dendrogram_plot(self, orientation): # Tests dendrogram plotting. Z = linkage(hierarchy_test_data.ytdist, 'single') expected = { 'color_list': ['g', 'b', 'b', 'b', 'b'], 'dcoord': [[0.0, 138.0, 138.0, 0.0], [0.0, 219.0, 219.0, 0.0], [0.0, 255.0, 255.0, 219.0], [0.0, 268.0, 268.0, 255.0], [138.0, 295.0, 295.0, 268.0]], 'icoord': [[5.0, 5.0, 15.0, 15.0], [45.0, 45.0, 55.0, 55.0], [35.0, 35.0, 50.0, 50.0], [25.0, 25.0, 42.5, 42.5], [10.0, 10.0, 33.75, 33.75]], 'ivl': ['2', '5', '1', '0', '3', '4'], 'leaves': [2, 5, 1, 0, 3, 4] } fig = plt.figure() ax = fig.add_subplot(111) # test that dendrogram accepts ax keyword R1 = dendrogram(Z, ax=ax, orientation=orientation) plt.close() assert_equal(R1, expected) # test plotting to gca (will import pylab) R2 = dendrogram(Z, orientation=orientation) plt.close() assert_equal(R2, expected)
def test_dendrogram_truncate_mode(self): Z = linkage(hierarchy_test_data.ytdist, 'single') R = dendrogram(Z, 2, 'lastp', show_contracted=True) plt.close() assert_equal( R, { 'color_list': ['b'], 'dcoord': [[0.0, 295.0, 295.0, 0.0]], 'icoord': [[5.0, 5.0, 15.0, 15.0]], 'ivl': ['(2)', '(4)'], 'leaves': [6, 9] }) R = dendrogram(Z, 2, 'mtica', show_contracted=True) plt.close() assert_equal( R, { 'color_list': ['g', 'b', 'b', 'b'], 'dcoord': [[0.0, 138.0, 138.0, 0.0], [0.0, 255.0, 255.0, 0.0], [0.0, 268.0, 268.0, 255.0], [138.0, 295.0, 295.0, 268.0]], 'icoord': [[5.0, 5.0, 15.0, 15.0], [35.0, 35.0, 45.0, 45.0], [25.0, 25.0, 40.0, 40.0], [10.0, 10.0, 32.5, 32.5]], 'ivl': ['2', '5', '1', '0', '(2)'], 'leaves': [2, 5, 1, 0, 7] })
def check_dendrogram_plot(self, orientation): # Tests dendrogram plotting. Z = linkage(hierarchy_test_data.ytdist, 'single') expected = {'color_list': ['g', 'b', 'b', 'b', 'b'], 'dcoord': [[0.0, 138.0, 138.0, 0.0], [0.0, 219.0, 219.0, 0.0], [0.0, 255.0, 255.0, 219.0], [0.0, 268.0, 268.0, 255.0], [138.0, 295.0, 295.0, 268.0]], 'icoord': [[5.0, 5.0, 15.0, 15.0], [45.0, 45.0, 55.0, 55.0], [35.0, 35.0, 50.0, 50.0], [25.0, 25.0, 42.5, 42.5], [10.0, 10.0, 33.75, 33.75]], 'ivl': ['2', '5', '1', '0', '3', '4'], 'leaves': [2, 5, 1, 0, 3, 4]} fig = plt.figure() ax = fig.add_subplot(111) # test that dendrogram accepts ax keyword R1 = dendrogram(Z, ax=ax, orientation=orientation) plt.close() assert_equal(R1, expected) # test plotting to gca (will import pylab) R2 = dendrogram(Z, orientation=orientation) plt.close() assert_equal(R2, expected)
def test_dendrogram_colors(self): # Tests dendrogram plots with alternate colors Z = linkage(hierarchy_test_data.ytdist, 'single') set_link_color_palette(['c', 'm', 'y', 'k']) R = dendrogram(Z, no_plot=True, above_threshold_color='g', color_threshold=250) set_link_color_palette(['g', 'r', 'c', 'm', 'y', 'k']) color_list = R['color_list'] assert_equal(color_list, ['c', 'm', 'g', 'g', 'g'])
def test_dendrogram_truncate_mode(self): Z = linkage(hierarchy_test_data.ytdist, 'single') R = dendrogram(Z, 2, 'lastp', show_contracted=True) plt.close() assert_equal(R, {'color_list': ['b'], 'dcoord': [[0.0, 295.0, 295.0, 0.0]], 'icoord': [[5.0, 5.0, 15.0, 15.0]], 'ivl': ['(2)', '(4)'], 'leaves': [6, 9]}) R = dendrogram(Z, 2, 'mtica', show_contracted=True) plt.close() assert_equal(R, {'color_list': ['g', 'b', 'b', 'b'], 'dcoord': [[0.0, 138.0, 138.0, 0.0], [0.0, 255.0, 255.0, 0.0], [0.0, 268.0, 268.0, 255.0], [138.0, 295.0, 295.0, 268.0]], 'icoord': [[5.0, 5.0, 15.0, 15.0], [35.0, 35.0, 45.0, 45.0], [25.0, 25.0, 40.0, 40.0], [10.0, 10.0, 32.5, 32.5]], 'ivl': ['2', '5', '1', '0', '(2)'], 'leaves': [2, 5, 1, 0, 7]})
def test_dendrogram_single_linkage_tdist(self): # Tests dendrogram calculation on single linkage of the tdist data set. Z = linkage(hierarchy_test_data.ytdist, 'single') R = dendrogram(Z, no_plot=True) leaves = R["leaves"] assert_equal(leaves, [2, 5, 1, 0, 3, 4])