1
1
from unittest import TestCase
2
2
from plotly .graph_objs import graph_objs as go
3
3
from plotly .exceptions import PlotlyError
4
- import plotly .graph_objs .figure_factory
4
+ from plotly .graph_objs .figure_factory import FigureFactory
5
5
6
6
import plotly .tools as tls
7
7
from plotly .tests .test_optional .optional_utils import NumpyTestUtilsMixin
@@ -22,7 +22,7 @@ def test_wrong_curve_type(self):
22
22
'curve_type' : 'curve' }
23
23
self .assertRaisesRegexp (PlotlyError , "curve_type must be defined as "
24
24
"'kde' or 'normal'" ,
25
- plotly . graph_objs . figure_factory . FigureFactory .create_distplot , ** kwargs )
25
+ FigureFactory .create_distplot , ** kwargs )
26
26
27
27
def test_wrong_histdata_format (self ):
28
28
@@ -31,25 +31,25 @@ def test_wrong_histdata_format(self):
31
31
# will fail)
32
32
33
33
kwargs = {'hist_data' : [1 , 2 , 3 ], 'group_labels' : ['group' ]}
34
- self .assertRaises (PlotlyError , plotly . graph_objs . figure_factory . FigureFactory .create_distplot ,
34
+ self .assertRaises (PlotlyError , FigureFactory .create_distplot ,
35
35
** kwargs )
36
36
37
37
def test_unequal_data_label_length (self ):
38
38
kwargs = {'hist_data' : [[1 , 2 ]], 'group_labels' : ['group' , 'group2' ]}
39
- self .assertRaises (PlotlyError , plotly . graph_objs . figure_factory . FigureFactory .create_distplot ,
39
+ self .assertRaises (PlotlyError , FigureFactory .create_distplot ,
40
40
** kwargs )
41
41
42
42
kwargs = {'hist_data' : [[1 , 2 ], [1 , 2 , 3 ]], 'group_labels' : ['group' ]}
43
- self .assertRaises (PlotlyError , plotly . graph_objs . figure_factory . FigureFactory .create_distplot ,
43
+ self .assertRaises (PlotlyError , FigureFactory .create_distplot ,
44
44
** kwargs )
45
45
46
46
def test_simple_distplot (self ):
47
47
48
48
# we should be able to create a single distplot with a simple dataset
49
49
# and default kwargs
50
50
51
- dp = plotly . graph_objs . figure_factory . FigureFactory .create_distplot (hist_data = [[1 , 2 , 2 , 3 ]],
52
- group_labels = ['distplot' ])
51
+ dp = FigureFactory .create_distplot (hist_data = [[1 , 2 , 2 , 3 ]],
52
+ group_labels = ['distplot' ])
53
53
expected_dp_layout = {'barmode' : 'overlay' ,
54
54
'hovermode' : 'closest' ,
55
55
'legend' : {'traceorder' : 'reversed' },
@@ -104,8 +104,8 @@ def test_distplot_more_args(self):
104
104
hist_data = [hist1_x ] + [hist2_x ]
105
105
group_labels = ['2012' , '2013' ]
106
106
107
- dp = plotly . graph_objs . figure_factory . FigureFactory .create_distplot (hist_data , group_labels ,
108
- show_rug = False , bin_size = .2 )
107
+ dp = FigureFactory .create_distplot (hist_data , group_labels ,
108
+ show_rug = False , bin_size = .2 )
109
109
dp ['layout' ].update (title = 'Dist Plot' )
110
110
111
111
expected_dp_layout = {'barmode' : 'overlay' ,
@@ -161,7 +161,7 @@ def test_wrong_arrow_scale(self):
161
161
'u' : [[- 1 , - 5 ], [- 1 , - 5 ]],
162
162
'v' : [[1 , 1 ], [- 3 , - 3 ]],
163
163
'arrow_scale' : 0 }
164
- self .assertRaises (ValueError , plotly . graph_objs . figure_factory . FigureFactory .create_streamline ,
164
+ self .assertRaises (ValueError , FigureFactory .create_streamline ,
165
165
** kwargs )
166
166
167
167
def test_wrong_density (self ):
@@ -172,7 +172,7 @@ def test_wrong_density(self):
172
172
'u' : [[- 1 , - 5 ], [- 1 , - 5 ]],
173
173
'v' : [[1 , 1 ], [- 3 , - 3 ]],
174
174
'density' : 0 }
175
- self .assertRaises (ValueError , plotly . graph_objs . figure_factory . FigureFactory .create_streamline ,
175
+ self .assertRaises (ValueError , FigureFactory .create_streamline ,
176
176
** kwargs )
177
177
178
178
def test_uneven_x (self ):
@@ -182,7 +182,7 @@ def test_uneven_x(self):
182
182
kwargs = {'x' : [0 , 2 , 7 , 9 ], 'y' : [0 , 2 , 4 , 6 ],
183
183
'u' : [[- 1 , - 5 ], [- 1 , - 5 ]],
184
184
'v' : [[1 , 1 ], [- 3 , - 3 ]]}
185
- self .assertRaises (PlotlyError , plotly . graph_objs . figure_factory . FigureFactory .create_streamline ,
185
+ self .assertRaises (PlotlyError , FigureFactory .create_streamline ,
186
186
** kwargs )
187
187
188
188
def test_uneven_y (self ):
@@ -192,7 +192,7 @@ def test_uneven_y(self):
192
192
kwargs = {'x' : [0 , 2 , 4 , 6 ], 'y' : [1.5 , 2 , 3 , 3.5 ],
193
193
'u' : [[- 1 , - 5 ], [- 1 , - 5 ]],
194
194
'v' : [[1 , 1 ], [- 3 , - 3 ]]}
195
- self .assertRaises (PlotlyError , plotly . graph_objs . figure_factory . FigureFactory .create_streamline ,
195
+ self .assertRaises (PlotlyError , FigureFactory .create_streamline ,
196
196
** kwargs )
197
197
198
198
def test_unequal_length_xy (self ):
@@ -202,7 +202,7 @@ def test_unequal_length_xy(self):
202
202
kwargs = {'x' : [0 , 2 , 4 , 6 ], 'y' : [1.5 , 2 , 3.5 ],
203
203
'u' : [[- 1 , - 5 ], [- 1 , - 5 ]],
204
204
'v' : [[1 , 1 ], [- 3 , - 3 ]]}
205
- self .assertRaises (PlotlyError , plotly . graph_objs . figure_factory . FigureFactory .create_streamline ,
205
+ self .assertRaises (PlotlyError , FigureFactory .create_streamline ,
206
206
** kwargs )
207
207
208
208
def test_unequal_length_uv (self ):
@@ -212,7 +212,7 @@ def test_unequal_length_uv(self):
212
212
kwargs = {'x' : [0 , 2 , 4 , 6 ], 'y' : [1.5 , 2 , 3 , 3.5 ],
213
213
'u' : [[- 1 , - 5 ], [- 1 , - 5 ], [- 1 , - 5 ]],
214
214
'v' : [[1 , 1 ], [- 3 , - 3 ]]}
215
- self .assertRaises (PlotlyError , plotly . graph_objs . figure_factory . FigureFactory .create_streamline ,
215
+ self .assertRaises (PlotlyError , FigureFactory .create_streamline ,
216
216
** kwargs )
217
217
218
218
def test_simple_streamline (self ):
@@ -228,14 +228,14 @@ def test_simple_streamline(self):
228
228
# u = u.T #transpose
229
229
# v = v.T #transpose
230
230
231
- strln = plotly . graph_objs . figure_factory . FigureFactory .create_streamline (x = [- 1. , 0. , 1. ],
232
- y = [- 1. , 0. , 1. ],
233
- u = [[1. , 0. , 1. ],
234
- [1. , 0. , 1. ],
235
- [1. , 0. , 1. ]],
236
- v = [[1. , 1. , 1. ],
237
- [0. , 0. , 0. ],
238
- [1. , 1. , 1. ]])
231
+ strln = FigureFactory .create_streamline (x = [- 1. , 0. , 1. ],
232
+ y = [- 1. , 0. , 1. ],
233
+ u = [[1. , 0. , 1. ],
234
+ [1. , 0. , 1. ],
235
+ [1. , 0. , 1. ]],
236
+ v = [[1. , 1. , 1. ],
237
+ [0. , 0. , 0. ],
238
+ [1. , 1. , 1. ]])
239
239
expected_strln_0_100 = {
240
240
'y' : [- 1.0 , - 0.9788791845863757 , - 0.9579399744939614 , - 0.9371777642073374 , - 0.9165881396413338 , - 0.8961668671832106 , - 0.8759098835283448 , - 0.8558132862403048 , - 0.835873324973195 , - 0.8160863933003534 , - 0.7964490210989816 , - 0.7769578674451656 , - 0.7576097139780906 , - 0.7384014586961288 , - 0.7193301101509343 , - 0.7003927820087748 , - 0.681586687951103 , - 0.6629091368888596 , - 0.64435752846723 , - 0.6259293488396024 , - 0.6076221666912738 , - 0.5894336294951057 , - 0.5713614599827976 , - 0.5534034528167977 , - 0.5355574714490806 , - 0.5178214451541254 , - 0.5001933662244311 , - 0.4826712873178177 , - 0.4652533189465894 , - 0.44793762709939944 , - 0.4307224309873414 , - 0.4136060009064273 , - 0.39658665620919065 , - 0.3796627633786812 , - 0.3628327341986042 , - 0.34609502401380254 , - 0.3294481300756896 , - 0.31289058996761565 , - 0.2964209801054992 , - 0.28003791430937197 , - 0.2637400424417804 , - 0.24752604910925968 , - 0.23139465242334434 , - 0.21534460281781365 , - 0.19937468191908325 , - 0.18348370146685278 , - 0.1676705022823033 , - 0.15193395328130999 , - 0.13627295053029143 , - 0.1206864163424669 , - 0.10517329841242584 , - 0.08973256898704507 , - 0.07436322407090357 , - 0.05906428266445696 , - 0.04383478603333624 , - 0.028673797007230273 , - 0.013580399306900914 , 0.0014484211645073852 , 0.01648792568956914 , 0.03159429687713278 , 0.04676843461935776 , 0.062011259175942746 , 0.07732371182540754 , 0.09270675554339824 , 0.10816137570939799 , 0.12368858084331191 , 0.1392894033734846 , 0.1549649004378033 , 0.1707161547196483 , 0.1865442753205595 , 0.20245039867161063 , 0.21843568948560943 , 0.23450134175238246 , 0.25064857977955146 , 0.26687865928136767 , 0.2831928685183458 , 0.29959252949062387 , 0.3160789991881776 , 0.33265367090123643 , 0.3493179755944802 , 0.366073383348855 , 0.3829214048751186 , 0.39986359310352526 , 0.41690154485438513 , 0.4340369025945845 , 0.4512713562855355 , 0.46860664532844054 , 0.4860445606132082 , 0.5035869466778524 , 0.5212357039857456 , 0.5389927913286829 , 0.5568602283643591 , 0.5748400982975623 , 0.5929345507151613 , 0.6111458045858065 , 0.6294761514361948 , 0.6479279587167714 , 0.6665036733708583 , 0.6852058256224467 , 0.704037032999252 ],
241
241
'x' : [- 1.0 , - 0.9788791845863756 , - 0.9579399744939614 , - 0.9371777642073374 , - 0.9165881396413338 , - 0.8961668671832106 , - 0.8759098835283448 , - 0.8558132862403048 , - 0.835873324973195 , - 0.8160863933003534 , - 0.7964490210989816 , - 0.7769578674451656 , - 0.7576097139780906 , - 0.7384014586961289 , - 0.7193301101509344 , - 0.7003927820087748 , - 0.6815866879511031 , - 0.6629091368888596 , - 0.6443575284672302 , - 0.6259293488396025 , - 0.6076221666912739 , - 0.5894336294951058 , - 0.5713614599827976 , - 0.5534034528167978 , - 0.5355574714490807 , - 0.5178214451541254 , - 0.5001933662244312 , - 0.4826712873178177 , - 0.4652533189465894 , - 0.44793762709939944 , - 0.4307224309873414 , - 0.4136060009064273 , - 0.39658665620919065 , - 0.3796627633786812 , - 0.3628327341986042 , - 0.34609502401380254 , - 0.3294481300756896 , - 0.31289058996761565 , - 0.2964209801054992 , - 0.28003791430937197 , - 0.2637400424417804 , - 0.24752604910925968 , - 0.23139465242334434 , - 0.21534460281781365 , - 0.19937468191908325 , - 0.18348370146685278 , - 0.1676705022823033 , - 0.15193395328130999 , - 0.13627295053029143 , - 0.1206864163424669 , - 0.10517329841242584 , - 0.08973256898704507 , - 0.07436322407090357 , - 0.05906428266445696 , - 0.04383478603333624 , - 0.028673797007230273 , - 0.013580399306900914 , 0.0014484211645073852 , 0.01648792568956914 , 0.03159429687713278 , 0.04676843461935776 , 0.062011259175942746 , 0.07732371182540754 , 0.09270675554339824 , 0.10816137570939799 , 0.12368858084331191 , 0.1392894033734846 , 0.1549649004378033 , 0.1707161547196483 , 0.1865442753205595 , 0.20245039867161063 , 0.21843568948560943 , 0.23450134175238246 , 0.25064857977955146 , 0.26687865928136767 , 0.2831928685183458 , 0.29959252949062387 , 0.3160789991881776 , 0.33265367090123643 , 0.3493179755944802 , 0.366073383348855 , 0.3829214048751186 , 0.39986359310352526 , 0.41690154485438513 , 0.4340369025945845 , 0.4512713562855355 , 0.46860664532844054 , 0.4860445606132082 , 0.5035869466778524 , 0.5212357039857456 , 0.5389927913286829 , 0.5568602283643591 , 0.5748400982975623 , 0.5929345507151613 , 0.6111458045858065 , 0.6294761514361948 , 0.6479279587167714 , 0.6665036733708583 , 0.6852058256224467 , 0.704037032999252 ],
@@ -252,7 +252,7 @@ class TestDendrogram(NumpyTestUtilsMixin, TestCase):
252
252
253
253
def test_default_dendrogram (self ):
254
254
X = np .array ([[1 , 2 , 3 , 4 ], [1 , 1 , 3 , 4 ], [1 , 2 , 1 , 4 ], [1 , 2 , 3 , 1 ]])
255
- dendro = plotly . graph_objs . figure_factory . FigureFactory .create_dendrogram (X = X )
255
+ dendro = FigureFactory .create_dendrogram (X = X )
256
256
257
257
expected_dendro = go .Figure (
258
258
data = go .Data ([
@@ -331,7 +331,7 @@ def test_dendrogram_random_matrix(self):
331
331
X [2 , :] = sum (X , 0 )
332
332
333
333
names = ['Jack' , 'Oxana' , 'John' , 'Chelsea' , 'Mark' ]
334
- dendro = plotly . graph_objs . figure_factory . FigureFactory .create_dendrogram (X , labels = names )
334
+ dendro = FigureFactory .create_dendrogram (X , labels = names )
335
335
336
336
expected_dendro = go .Figure (
337
337
data = go .Data ([
@@ -425,26 +425,26 @@ def test_dendrogram_random_matrix(self):
425
425
def test_dendrogram_orientation (self ):
426
426
X = np .random .rand (5 , 5 )
427
427
428
- dendro_left = plotly . graph_objs . figure_factory . FigureFactory .create_dendrogram (
428
+ dendro_left = FigureFactory .create_dendrogram (
429
429
X , orientation = 'left' )
430
430
self .assertEqual (len (dendro_left ['layout' ]['yaxis' ]['ticktext' ]), 5 )
431
431
tickvals_left = np .array (dendro_left ['layout' ]['yaxis' ]['tickvals' ])
432
432
self .assertTrue ((tickvals_left <= 0 ).all ())
433
433
434
- dendro_right = plotly . graph_objs . figure_factory . FigureFactory .create_dendrogram (
434
+ dendro_right = FigureFactory .create_dendrogram (
435
435
X , orientation = 'right' )
436
436
tickvals_right = np .array (dendro_right ['layout' ]['yaxis' ]['tickvals' ])
437
437
self .assertTrue ((tickvals_right >= 0 ).all ())
438
438
439
- dendro_bottom = plotly . graph_objs . figure_factory . FigureFactory .create_dendrogram (
439
+ dendro_bottom = FigureFactory .create_dendrogram (
440
440
X , orientation = 'bottom' )
441
441
self .assertEqual (len (dendro_bottom ['layout' ]['xaxis' ]['ticktext' ]), 5 )
442
442
tickvals_bottom = np .array (
443
443
dendro_bottom ['layout' ]['xaxis' ]['tickvals' ]
444
444
)
445
445
self .assertTrue ((tickvals_bottom >= 0 ).all ())
446
446
447
- dendro_top = plotly . graph_objs . figure_factory . FigureFactory .create_dendrogram (X , orientation = 'top' )
447
+ dendro_top = FigureFactory .create_dendrogram (X , orientation = 'top' )
448
448
tickvals_top = np .array (dendro_top ['layout' ]['xaxis' ]['tickvals' ])
449
449
self .assertTrue ((tickvals_top <= 0 ).all ())
450
450
@@ -463,7 +463,7 @@ def test_dendrogram_colorscale(self):
463
463
'rgb(220,220,220)' , # gainsboro
464
464
'rgb(245,245,245)' ] # white smoke
465
465
466
- dendro = plotly . graph_objs . figure_factory . FigureFactory .create_dendrogram (X , colorscale = greyscale )
466
+ dendro = FigureFactory .create_dendrogram (X , colorscale = greyscale )
467
467
468
468
expected_dendro = go .Figure (
469
469
data = go .Data ([
0 commit comments