20
20
from plotly import exceptions
21
21
from plotly import session
22
22
23
- from plotly .graph_objs import graph_objs
24
- from plotly .graph_objs import Scatter , Marker , Line , Data
23
+ from plotly .graph_objs import graph_objs , Scatter , Marker , Line , Data
25
24
26
25
27
26
# Warning format
@@ -52,13 +51,23 @@ def warning_on_one_line(message, category, filename, lineno,
52
51
53
52
try :
54
53
import scipy as scp
55
- import scipy .spatial as scs
56
- import scipy .cluster .hierarchy as sch
57
-
58
54
_scipy_imported = True
59
55
except ImportError :
60
56
_scipy_imported = False
61
57
58
+ try :
59
+ import scipy .spatial as scs
60
+ _scipy__spatial_imported = True
61
+ except ImportError :
62
+ _scipy__spatial_imported = False
63
+
64
+ try :
65
+ import scipy .cluster .hierarchy as sch
66
+ _scipy__cluster__hierarchy_imported = True
67
+ except ImportError :
68
+ _scipy__cluster__hierarchy_imported = False
69
+
70
+
62
71
PLOTLY_DIR = os .path .join (os .path .expanduser ("~" ), ".plotly" )
63
72
CREDENTIALS_FILE = os .path .join (PLOTLY_DIR , ".credentials" )
64
73
CONFIG_FILE = os .path .join (PLOTLY_DIR , ".config" )
@@ -2323,10 +2332,12 @@ def create_dendrogram(X, orientation="bottom", labels=None,
2323
2332
py.iplot(dendro_X, validate=False, height=1000, width=300)
2324
2333
```
2325
2334
"""
2326
-
2327
- if _scipy_imported is False :
2328
- raise ImportError ("FigureFactory .create_dendrogram requires scipy ,
2329
- scipy .spatial and scipy .hierarchy " )
2335
+ dependencies = (_scipy_imported and _scipy__spatial_imported and
2336
+ _scipy__cluster__hierarchy_imported )
2337
+
2338
+ if dependencies is False :
2339
+ raise ImportError ("FigureFactory.create_dendrogram requires scipy, \
2340
+ scipy.spatial and scipy.hierarchy" )
2330
2341
2331
2342
s = X .shape
2332
2343
if len (s ) != 2 :
@@ -2934,14 +2945,15 @@ def get_candle_decrease(self):
2934
2945
return (decrease_x , decrease_close , decrease_dif ,
2935
2946
stick_decrease_y , stick_decrease_x )
2936
2947
2948
+
2937
2949
class _Dendrogram (FigureFactory ):
2938
-
2950
+
2939
2951
"""
2940
2952
Refer to FigureFactory.create_dendrogram() for docstring.
2941
2953
"""
2942
2954
2943
- def __init__ (self , X , orientation = 'bottom' , labels = None , colorscale = None , \
2944
- width = "100%" , height = "100%" , xaxis = 'xaxis' , yaxis = 'yaxis' ):
2955
+ def __init__ (self , X , orientation = 'bottom' , labels = None , colorscale = None ,
2956
+ width = "100%" , height = "100%" , xaxis = 'xaxis' , yaxis = 'yaxis' ):
2945
2957
self .orientation = orientation
2946
2958
self .labels = labels
2947
2959
self .xaxis = xaxis
@@ -2961,8 +2973,8 @@ def __init__(self, X, orientation='bottom', labels=None, colorscale=None, \
2961
2973
else :
2962
2974
self .sign [self .yaxis ] = - 1
2963
2975
2964
- dd_traces , xvals , yvals ,
2965
- ordered_labels , leaves = self .get_dendrogram_traces (X , colorscale )
2976
+ ( dd_traces , xvals , yvals ,
2977
+ ordered_labels , leaves ) = self .get_dendrogram_traces (X , colorscale )
2966
2978
2967
2979
self .labels = ordered_labels
2968
2980
self .leaves = leaves
0 commit comments