10
10
import os
11
11
import requests
12
12
13
- import plotly .plotly as py
14
13
from plotly import utils
15
14
from plotly import tools
16
15
from plotly .exceptions import PlotlyError
16
+ from plotly import session
17
17
18
- _PLOTLY_OFFLINE_DIRECTORY = plotlyjs_path = os .path .expanduser (
18
+ PLOTLY_OFFLINE_DIRECTORY = plotlyjs_path = os .path .expanduser (
19
19
os .path .join (* '~/.plotly/plotlyjs' .split ('/' )))
20
- _PLOTLY_OFFLINE_BUNDLE = os .path .join (_PLOTLY_OFFLINE_DIRECTORY ,
21
- 'plotly-ipython-offline-bundle.js' )
20
+ PLOTLY_OFFLINE_BUNDLE = os .path .join (PLOTLY_OFFLINE_DIRECTORY ,
21
+ 'plotly-ipython-offline-bundle.js' )
22
+
22
23
23
24
__PLOTLY_OFFLINE_INITIALIZED = False
24
25
25
26
26
27
def download_plotlyjs (download_url ):
27
- if not os .path .exists (plotlyjs_path ):
28
- os .makedirs (plotlyjs_path )
28
+ if not os .path .exists (PLOTLY_OFFLINE_DIRECTORY ):
29
+ os .makedirs (PLOTLY_OFFLINE_DIRECTORY )
29
30
30
31
res = requests .get (download_url )
31
32
res .raise_for_status ()
32
33
33
- with open (_PLOTLY_OFFLINE_BUNDLE , 'wb' ) as f :
34
+ with open (PLOTLY_OFFLINE_BUNDLE , 'wb' ) as f :
34
35
f .write (res .content )
35
36
36
37
print ('\n ' .join ([
@@ -55,7 +56,7 @@ def init_notebook_mode():
55
56
raise ImportError ('`iplot` can only run inside an IPython Notebook.' )
56
57
from IPython .display import HTML , display
57
58
58
- if not os .path .exists (_PLOTLY_OFFLINE_BUNDLE ):
59
+ if not os .path .exists (PLOTLY_OFFLINE_BUNDLE ):
59
60
raise PlotlyError ('Plotly Offline source file at {source_path} '
60
61
'is not found.\n '
61
62
'If you have a Plotly Offline license, then try '
@@ -64,12 +65,12 @@ def init_notebook_mode():
64
65
"Don't have a Plotly Offline license? "
65
66
'Contact sales@plot.ly learn more about licensing.\n '
66
67
'Questions? support@plot.ly.'
67
- .format (source_path = _PLOTLY_OFFLINE_BUNDLE ))
68
+ .format (source_path = PLOTLY_OFFLINE_BUNDLE ))
68
69
69
70
global __PLOTLY_OFFLINE_INITIALIZED
70
71
__PLOTLY_OFFLINE_INITIALIZED = True
71
72
display (HTML ('<script type="text/javascript">' +
72
- open (_PLOTLY_OFFLINE_BUNDLE ).read () + '</script>' ))
73
+ open (PLOTLY_OFFLINE_BUNDLE ).read () + '</script>' ))
73
74
74
75
75
76
def iplot (figure_or_data , show_link = True , link_text = 'Export to plot.ly' ):
@@ -142,8 +143,8 @@ def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly'):
142
143
if show_link is False :
143
144
link_text = ''
144
145
145
- plotly_platform_url = py . get_config ().get ('plotly_domain' ,
146
- 'https://plot.ly' )
146
+ plotly_platform_url = session . get_session_config ().get ('plotly_domain' ,
147
+ 'https://plot.ly' )
147
148
if (plotly_platform_url != 'https://plot.ly' and
148
149
link_text == 'Export to plot.ly' ):
149
150
@@ -185,3 +186,4 @@ def plot():
185
186
""" Configured to work with localhost Plotly graph viewer
186
187
"""
187
188
raise NotImplementedError
189
+
0 commit comments