@@ -16,13 +16,13 @@ def signup(un, email):
16
16
'''
17
17
payload = {'version' : __version__ , 'un' : un , 'email' : email , 'platform' :'Python' }
18
18
r = requests .post ('https://plot.ly/apimkacct' , data = payload )
19
+ r .raise_for_status ()
19
20
r = json .loads (r .text )
20
- if 'error' in r .keys ():
21
- if not r ['error' ] == '' :
22
- print (r ['error' ])
23
- if 'warning' in r .keys ():
24
- print (r ['warning' ])
25
- if 'message' in r .keys ():
21
+ if 'error' in r and r ['error' ] != '' :
22
+ print (r ['error' ])
23
+ if 'warning' in r and r ['warning' ] != '' :
24
+ warnings .warn (r ['warning' ])
25
+ if 'message' in r and r ['message' ] != '' :
26
26
print (r ['message' ])
27
27
28
28
return r
@@ -36,13 +36,18 @@ def __init__(self, username=None, key=None,verbose=True):
36
36
self .__filename = None
37
37
self .__fileopt = None
38
38
self .verbose = verbose
39
+ self .open = True
40
+
41
+ def ion (self ):
42
+ self .open = True
43
+ def ioff (self ):
39
44
self .open = False
40
45
41
46
def iplot (self , * args , ** kwargs ):
42
47
''' for use in ipython notebooks '''
43
48
res = self .__callplot (* args , ** kwargs )
44
49
width = kwargs .get ('width' , 600 )
45
- height = kwargs .get ('height' , 600 )
50
+ height = kwargs .get ('height' , 450 )
46
51
s = '<iframe height="%s" id="igraph" scrolling="no" seamless="seamless" src="%s" width="%s"></iframe>' % \
47
52
(height + 50 , "/" .join (map (str , [res ['url' ], width , height ])), width + 50 )
48
53
try :
@@ -59,7 +64,7 @@ def iplot(self, *args, **kwargs):
59
64
60
65
def plot (self , * args , ** kwargs ):
61
66
res = self .__callplot (* args , ** kwargs )
62
- if res ['error' ] == '' and self .open :
67
+ if 'error' in res and res ['error' ] == '' and self .open :
63
68
from webbrowser import open as wbopen
64
69
wbopen (res ['url' ])
65
70
return res
@@ -69,7 +74,7 @@ def __callplot(self, *args, **kwargs):
69
74
Two interfaces:
70
75
1 - ploty.plot(x1, y1[,x2,y2,...],**kwargs)
71
76
where x1, y1, .... are lists, numpy arrays
72
- 2 - plot.plot([data1, ...], **kwargs)
77
+ 2 - plot.plot([data1[, data2 , ...], **kwargs)
73
78
where data1 is a dict that is at least
74
79
{'x': x1, 'y': y1} but can contain more styling and sharing options.
75
80
kwargs accepts:
@@ -83,14 +88,14 @@ def __callplot(self, *args, **kwargs):
83
88
:param r['filename']: The filename of the plot in your plotly account.
84
89
'''
85
90
86
- un = kwargs ['un' ] if 'un' in kwargs . keys () else self .un
87
- key = kwargs ['key' ] if 'key' in kwargs . keys () else self .key
91
+ un = kwargs ['un' ] if 'un' in kwargs else self .un
92
+ key = kwargs ['key' ] if 'key' in kwargs else self .key
88
93
if not un or not key :
89
94
raise Exception ('Not Signed in' )
90
95
91
- if not 'filename' in kwargs . keys () :
96
+ if not 'filename' in kwargs :
92
97
kwargs ['filename' ] = self .__filename
93
- if not 'fileopt' in kwargs . keys () :
98
+ if not 'fileopt' in kwargs :
94
99
kwargs ['fileopt' ] = self .__fileopt
95
100
96
101
origin = 'plot'
@@ -208,6 +213,7 @@ def __makecall(self, args, un, key, origin, kwargs):
208
213
url = 'https://plot.ly/clientresp'
209
214
payload = {'platform' : platform , 'version' : __version__ , 'args' : args , 'un' : un , 'key' : key , 'origin' : origin , 'kwargs' : kwargs }
210
215
r = requests .post (url , data = payload )
216
+ r .raise_for_status ()
211
217
r = json .loads (r .text )
212
218
if 'error' in r and r ['error' ] != '' :
213
219
print (r ['error' ])
0 commit comments