@@ -16,13 +16,13 @@ def signup(un, email):
1616	''' 
1717	payload  =  {'version' : __version__ , 'un' : un , 'email' : email , 'platform' :'Python' }
1818	r  =  requests .post ('https://plot.ly/apimkacct' , data = payload )
19+ 	r .raise_for_status ()
1920	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' ] !=  '' :
2626		print (r ['message' ])
2727
2828	return  r 
@@ -36,13 +36,18 @@ def __init__(self, username=None, key=None,verbose=True):
3636		self .__filename  =  None 
3737		self .__fileopt  =  None 
3838		self .verbose  =  verbose 
39+ 		self .open  =  True 
40+ 
41+ 	def  ion (self ):
42+ 		self .open  =  True 
43+ 	def  ioff (self ):
3944		self .open  =  False 
4045
4146	def  iplot (self , * args , ** kwargs ):
4247		''' for use in ipython notebooks ''' 
4348		res  =  self .__callplot (* args , ** kwargs )
4449		width  =  kwargs .get ('width' , 600 )
45- 		height  =  kwargs .get ('height' , 600 )
50+ 		height  =  kwargs .get ('height' , 450 )
4651		s  =  '<iframe height="%s" id="igraph" scrolling="no" seamless="seamless" src="%s" width="%s"></iframe>'  % \
4752			(height + 50 , "/" .join (map (str , [res ['url' ], width , height ])), width + 50 )
4853		try :
@@ -59,7 +64,7 @@ def iplot(self, *args, **kwargs):
5964
6065	def  plot (self , * args , ** kwargs ):
6166		res  =  self .__callplot (* args , ** kwargs )
62- 		if  res ['error' ] ==  ''  and  self .open :
67+ 		if  'error'   in   res   and   res ['error' ] ==  ''  and  self .open :
6368			from  webbrowser  import  open  as  wbopen 
6469			wbopen (res ['url' ])
6570		return  res 
@@ -69,7 +74,7 @@ def __callplot(self, *args, **kwargs):
6974		Two interfaces: 
7075			1 - ploty.plot(x1, y1[,x2,y2,...],**kwargs) 
7176			where x1, y1, .... are lists, numpy arrays 
72- 			2 - plot.plot([data1, ...], **kwargs) 
77+ 			2 - plot.plot([data1[, data2 , ...], **kwargs) 
7378			where data1 is a dict that is at least 
7479			{'x': x1, 'y': y1} but can contain more styling and sharing options. 
7580			kwargs accepts: 
@@ -83,14 +88,14 @@ def __callplot(self, *args, **kwargs):
8388			:param r['filename']: The filename of the plot in your plotly account. 
8489		''' 
8590
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 
8893		if  not  un  or  not  key :
8994			raise  Exception ('Not Signed in' )
9095
91- 		if  not  'filename'  in  kwargs . keys () :
96+ 		if  not  'filename'  in  kwargs :
9297			kwargs ['filename' ] =  self .__filename 
93- 		if  not  'fileopt'  in  kwargs . keys () :
98+ 		if  not  'fileopt'  in  kwargs :
9499			kwargs ['fileopt' ] =  self .__fileopt 
95100
96101		origin  =  'plot' 
@@ -208,6 +213,7 @@ def __makecall(self, args, un, key, origin, kwargs):
208213		url  =  'https://plot.ly/clientresp' 
209214		payload  =  {'platform' : platform , 'version' : __version__ , 'args' : args , 'un' : un , 'key' : key , 'origin' : origin , 'kwargs' : kwargs }
210215		r  =  requests .post (url , data = payload )
216+ 		r .raise_for_status ()
211217		r  =  json .loads (r .text )
212218		if  'error'  in  r  and  r ['error' ] !=  '' :
213219			print (r ['error' ])
0 commit comments