1
1
from unittest import TestCase
2
- from plotly .graph_objs import graph_objs , Line
2
+ from plotly .graph_objs import graph_objs as go
3
3
from plotly .exceptions import PlotlyError
4
4
5
5
import plotly .tools as tls
@@ -252,55 +252,66 @@ class TestDendrogram(NumpyTestUtilsMixin, TestCase):
252
252
def test_default_dendrogram (self ):
253
253
X = np .array ([[1 , 2 , 3 , 4 ], [1 , 1 , 3 , 4 ], [1 , 2 , 1 , 4 ], [1 , 2 , 3 , 1 ]])
254
254
dendro = tls .FigureFactory .create_dendrogram (X = X )
255
- expected_data = [{'marker' : {'color' : 'rgb(255,133,27)' },
256
- 'mode' : 'lines' , 'xaxis' : 'xs' ,
257
- 'yaxis' : 'y' ,
258
- 'y' : np .array ([0. , 1. , 1. , 0. ]),
259
- 'x' : np .array ([25. , 25. , 35. , 35. ]),
260
- 'type' : u'scatter' },
261
- {'marker' : {'color' : 'rgb(255,133,27)' },
262
- 'mode' : 'lines' ,
263
- 'xaxis' : 'x' ,
264
- 'yaxis' : 'y' ,
265
- 'y' : np .array ([0. , 2.23606798 , 2.23606798 , 1. ]),
266
- 'x' : np .array ([15. , 15. , 30. , 30. ]),
267
- 'type' : u'scatter' },
268
- {'marker' : {'color' : 'blue' },
269
- 'mode' : 'lines' ,
270
- 'xaxis' : 'x' ,
271
- 'yaxis' : 'y' ,
272
- 'y' : np .array ([0. , 3.60555128 ,
273
- 3.60555128 , 2.23606798 ]),
274
- 'x' : np .array ([5. , 5. , 22.5 , 22.5 ]),
275
- 'type' : u'scatter' }]
276
- expected_layout = {'width' : '100%' ,
277
- 'showlegend' : False ,
278
- 'autoscale' : False ,
279
- 'xaxis' : {'showticklabels' : True ,
280
- 'tickmode' : 'array' ,
281
- 'ticks' : 'outside' ,
282
- 'showgrid' : False ,
283
- 'mirror' : 'allticks' ,
284
- 'zeroline' : False ,
285
- 'showline' : True ,
286
- 'ticktext' : np .array (['3' , '2' ,
287
- '0' , '1' ],
288
- dtype = '|S1' ),
289
- 'rangemode' : 'tozero' ,
290
- 'type' : 'linear' ,
291
- 'tickvals' : np .array ([5.0 , 15.0 ,
292
- 25.0 , 35.0 ])},
293
- 'yaxis' : {'showticklabels' : True ,
294
- 'ticks' : 'outside' ,
295
- 'showgrid' : False ,
296
- 'mirror' : 'allticks' ,
297
- 'zeroline' : False ,
298
- 'showline' : True ,
299
- 'rangemode' : 'tozero' ,
300
- 'type' : 'linear' },
301
- 'hovermode' : 'closest' }
302
-
303
- expected_dendro = {'data' : expected_data , 'layout' : expected_layout }
255
+
256
+ expected_dendro = go .Figure (
257
+ data = go .Data ([
258
+ go .Scatter (
259
+ x = np .array ([25. , 25. , 35. , 35. ]),
260
+ y = np .array ([0. , 1. , 1. , 0. ]),
261
+ marker = go .Marker (color = 'rgb(61,153,112)' ),
262
+ mode = 'lines' ,
263
+ xaxis = 'x' ,
264
+ yaxis = 'y'
265
+ ),
266
+ go .Scatter (
267
+ x = np .array ([15. , 15. , 30. , 30. ]),
268
+ y = np .array ([0. , 2.23606798 , 2.23606798 , 1. ]),
269
+ marker = go .Marker (color = 'rgb(61,153,112)' ),
270
+ mode = 'lines' ,
271
+ xaxis = 'x' ,
272
+ yaxis = 'y'
273
+ ),
274
+ go .Scatter (
275
+ x = np .array ([5. , 5. , 22.5 , 22.5 ]),
276
+ y = np .array ([0. , 3.60555128 , 3.60555128 , 2.23606798 ]),
277
+ marker = go .Marker (color = 'rgb(0,116,217)' ),
278
+ mode = 'lines' ,
279
+ xaxis = 'x' ,
280
+ yaxis = 'y'
281
+ )
282
+ ]),
283
+ layout = go .Layout (
284
+ autosize = False ,
285
+ height = '100%' ,
286
+ hovermode = 'closest' ,
287
+ showlegend = False ,
288
+ width = '100%' ,
289
+ xaxis = go .XAxis (
290
+ mirror = 'allticks' ,
291
+ rangemode = 'tozero' ,
292
+ showgrid = False ,
293
+ showline = True ,
294
+ showticklabels = True ,
295
+ tickmode = 'array' ,
296
+ ticks = 'outside' ,
297
+ ticktext = np .array (['3' , '2' , '0' , '1' ], dtype = '|S1' ),
298
+ tickvals = [5.0 , 15.0 , 25.0 , 35.0 ],
299
+ type = 'linear' ,
300
+ zeroline = False
301
+ ),
302
+ yaxis = go .YAxis (
303
+ mirror = 'allticks' ,
304
+ rangemode = 'tozero' ,
305
+ showgrid = False ,
306
+ showline = True ,
307
+ showticklabels = True ,
308
+ ticks = 'outside' ,
309
+ type = 'linear' ,
310
+ zeroline = False
311
+ )
312
+ )
313
+ )
314
+
304
315
self .assertEqual (len (dendro ['data' ]), 3 )
305
316
306
317
# this is actually a bit clearer when debugging tests.
0 commit comments