@@ -115,29 +115,29 @@ def test_default_dendrogram(self):
115
115
[1 , 2 , 3 , 1 ]]))
116
116
expected_dendro_data = [{'marker' : {'color' : 'rgb(255,133,27)' },
117
117
'mode' : 'lines' , 'xaxis' : 'xs' ,
118
- 'yaxis' : 'ys ' ,
118
+ 'yaxis' : 'y ' ,
119
119
'y' : np .array ([0. , 1. , 1. , 0. ]),
120
120
'x' : np .array ([25. , 25. , 35. , 35. ]),
121
121
'type' : u'scatter' },
122
122
{'marker' : {'color' : 'rgb(255,133,27)' },
123
123
'mode' : 'lines' ,
124
- 'xaxis' : 'xs ' ,
125
- 'yaxis' : 'ys ' ,
124
+ 'xaxis' : 'x ' ,
125
+ 'yaxis' : 'y ' ,
126
126
'y' : np .array ([0. , 2.23606798 ,
127
127
2.23606798 , 1. ]),
128
128
'x' : np .array ([15. , 15. , 30. , 30. ]),
129
129
'type' : u'scatter' },
130
130
{'marker' : {'color' : 'blue' },
131
131
'mode' : 'lines' ,
132
- 'xaxis' : 'xs ' ,
133
- 'yaxis' : 'ys ' ,
132
+ 'xaxis' : 'x ' ,
133
+ 'yaxis' : 'y ' ,
134
134
'y' : np .array ([0. , 3.60555128 ,
135
135
3.60555128 , 2.23606798 ]),
136
136
'x' : np .array ([5. , 5. , 22.5 , 22.5 ]),
137
137
'type' : u'scatter' }]
138
138
139
139
self .assertEqual (len (dendro ['data' ]), len (expected_dendro_data ))
140
- self .assertTrue (np .array_equal (dendro ['labels ' ],
140
+ self .assertTrue (np .array_equal (dendro ['layout' ][ 'x' ][ 'ticktext ' ],
141
141
np .array (['3' , '2' , '0' , '1' ])))
142
142
143
143
for i in range (1 , len (dendro ['data' ])):
@@ -152,7 +152,32 @@ def test_dendrogram_random_matrix(self):
152
152
# variable 2 is correlated with all the other variables
153
153
X [2 , :] = sum (X , 0 )
154
154
155
- dendro = tls .FigureFactory .create_dendrogram (X )
155
+ names = ['Jack' , 'Oxana' , 'John' , 'Chelsea' , 'Mark' ]
156
+ dendro = tls .FigureFactory .create_dendrogram (X , labels = names )
156
157
157
- # Check that 2 is in a separate cluster
158
- self .assertEqual (dendro ['labels' ][0 ], '2' )
158
+ # Check that 2 is in a separate cluster and it's labelled correctly
159
+ self .assertEqual (dendro ['layout' ]['x' ]['ticktext' ][0 ], 'John' )
160
+
161
+ def test_dendrogram_orientation (self ):
162
+ X = np .random .rand (5 , 5 )
163
+
164
+ dendro_left = tls .FigureFactory .create_dendrogram (X , orientation = 'left' )
165
+
166
+ self .assertEqual (len (dendro_left ['layout' ]['y' ]['ticktext' ]), 5 )
167
+ tickvals_left = np .array (dendro_left ['layout' ]['y' ]['tickvals' ])
168
+ self .assertTrue ((tickvals_left <= 0 ).all ())
169
+
170
+ dendro_right = tls .FigureFactory .create_dendrogram (X , orientation = 'right' )
171
+ tickvals_right = np .array (dendro_right ['layout' ]['y' ]['tickvals' ])
172
+ self .assertTrue ((tickvals_right >= 0 ).all ())
173
+
174
+ dendro_bottom = tls .FigureFactory .create_dendrogram (X , orientation = 'bottom' )
175
+ self .assertEqual (len (dendro_bottom ['layout' ]['x' ]['ticktext' ]), 5 )
176
+ tickvals_bottom = np .array (dendro_bottom ['layout' ]['x' ]['tickvals' ])
177
+ self .assertTrue ((tickvals_bottom >= 0 ).all ())
178
+
179
+ dendro_top = tls .FigureFactory .create_dendrogram (X , orientation = 'top' )
180
+ tickvals_top = np .array (dendro_top ['layout' ]['x' ]['tickvals' ])
181
+ self .assertTrue ((tickvals_top <= 0 ).all ())
182
+
183
+
0 commit comments