Skip to content

Commit be3dab6

Browse files
authored
Merge pull request #562 from plotly/nteract
first pass at nteract support
2 parents 95fa17a + f65724f commit be3dab6

File tree

13 files changed

+426
-456
lines changed

13 files changed

+426
-456
lines changed

Diff for: CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

55
## [Unreleased]
6+
### Added
7+
- Support for rendering plots in [nteract](https://nteract.io/)!
8+
See [https://github.com/nteract/nteract/pull/662](https://github.com/nteract/nteract/pull/662)
9+
for the associated PR in nteract.
610

711
### Added
812
- `memoize` decorator added to `plotly.utils`

Diff for: plotly/offline/offline.py

+15-2
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly',
273273
validate=True, image=None, filename='plot_image', image_width=800,
274274
image_height=600):
275275
"""
276-
Draw plotly graphs inside an IPython notebook without
276+
Draw plotly graphs inside an IPython or Jupyter notebook without
277277
connecting to an external server.
278278
To save the chart to Plotly Cloud or Plotly Enterprise, use
279279
`plotly.plotly.iplot`.
@@ -335,7 +335,20 @@ def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly',
335335
figure_or_data, config, validate, '100%', 525, True
336336
)
337337

338-
ipython_display.display(ipython_display.HTML(plot_html))
338+
figure = tools.return_figure_from_figure_or_data(figure_or_data, validate)
339+
340+
# Though it can add quite a bit to the display-bundle size, we include
341+
# multiple representations of the plot so that the display environment can
342+
# choose which one to act on.
343+
data = _json.loads(_json.dumps(figure['data'],
344+
cls=plotly.utils.PlotlyJSONEncoder))
345+
layout = _json.loads(_json.dumps(figure.get('layout', {}),
346+
cls=plotly.utils.PlotlyJSONEncoder))
347+
display_bundle = {
348+
'application/vnd.plotly.v1+json': {'data': data, 'layout': layout},
349+
'text/html': plot_html
350+
}
351+
ipython_display.display(display_bundle, raw=True)
339352

340353
if image:
341354
if image not in __IMAGE_FORMATS:

Diff for: plotly/tests/test_core/test_file/test_file.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@
77
"""
88
import random
99
import string
10-
import requests
11-
from unittest import TestCase
1210

1311
from nose.plugins.attrib import attr
1412

1513
import plotly.plotly as py
1614
from plotly.exceptions import PlotlyRequestError
15+
from plotly.tests.utils import PlotlyTestCase
1716

1817

1918
@attr('slow')
20-
class FolderAPITestCase(TestCase):
19+
class FolderAPITestCase(PlotlyTestCase):
2120

2221
def setUp(self):
22+
super(FolderAPITestCase, self).setUp()
2323
py.sign_in('PythonTest', '9v9f20pext')
2424

2525
def _random_filename(self):

Diff for: plotly/tests/test_core/test_get_figure/test_get_figure.py

+56-79
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,12 @@
99

1010
from unittest import TestCase, skipIf
1111

12-
from nose.plugins.attrib import attr
13-
from nose.tools import raises
14-
1512
import six
13+
from nose.plugins.attrib import attr
1614

1715
from plotly import exceptions
18-
from plotly.graph_objs import graph_objs
1916
from plotly.plotly import plotly as py
20-
21-
# username for tests: 'plotlyimagetest'
22-
# api_key for account: '786r5mecv0'
17+
from plotly.tests.utils import PlotlyTestCase
2318

2419

2520
def is_trivial(obj):
@@ -41,75 +36,59 @@ def is_trivial(obj):
4136
return False
4237

4338

44-
@attr('slow')
45-
def test_get_figure():
46-
un = 'PlotlyImageTest'
47-
ak = '786r5mecv0'
48-
file_id = 2
49-
py.sign_in(un, ak)
50-
print("getting: https://plot.ly/~{0}/{1}/".format(un, file_id))
51-
print("###########################################\n\n")
52-
fig = py.get_figure('PlotlyImageTest', str(file_id))
53-
54-
55-
@attr('slow')
56-
def test_get_figure_with_url():
57-
un = 'PlotlyImageTest'
58-
ak = '786r5mecv0'
59-
url = "https://plot.ly/~PlotlyImageTest/2/"
60-
py.sign_in(un, ak)
61-
print("getting: https://plot.ly/~PlotlyImageTest/2/")
62-
print("###########################################\n\n")
63-
fig = py.get_figure(url)
64-
65-
66-
@raises(exceptions.PlotlyError)
67-
def test_get_figure_invalid_1():
68-
un = 'PlotlyImageTest'
69-
ak = '786r5mecv0'
70-
url = "https://plot.ly/~PlotlyImageTest/a/"
71-
py.sign_in(un, ak)
72-
print("not getting: https://plot.ly/~PlotlyImageTest/a/")
73-
print("###########################################\n\n")
74-
fig = py.get_figure(url)
75-
76-
77-
@attr('slow')
78-
@raises(exceptions.PlotlyError)
79-
def test_get_figure_invalid_2():
80-
un = 'PlotlyImageTest'
81-
ak = '786r5mecv0'
82-
url = "https://plot.ly/~PlotlyImageTest/-1/"
83-
py.sign_in(un, ak)
84-
print("not getting: https://plot.ly/~PlotlyImageTest/-1/")
85-
print("###########################################\n\n")
86-
fig = py.get_figure(url)
87-
88-
89-
@attr('slow')
90-
@raises(exceptions.PlotlyError)
91-
def test_get_figure_does_not_exist():
92-
un = 'PlotlyImageTest'
93-
ak = '786r5mecv0'
94-
url = "https://plot.ly/~PlotlyImageTest/1000000000/"
95-
py.sign_in(un, ak)
96-
print("not getting: https://plot.ly/~PlotlyImageTest/1000000000/")
97-
print("###########################################\n\n")
98-
fig = py.get_figure(url)
99-
100-
101-
@attr('slow')
102-
def test_get_figure_raw():
103-
un = 'PlotlyImageTest'
104-
ak = '786r5mecv0'
105-
file_id = 2
106-
py.sign_in(un, ak)
107-
print("getting: https://plot.ly/~{0}/{1}/".format(un, file_id))
108-
print("###########################################\n\n")
109-
fig = py.get_figure('PlotlyImageTest', str(file_id), raw=True)
110-
111-
112-
@attr('slow')
39+
class GetFigureTest(PlotlyTestCase):
40+
41+
@attr('slow')
42+
def test_get_figure(self):
43+
un = 'PlotlyImageTest'
44+
ak = '786r5mecv0'
45+
file_id = 2
46+
py.sign_in(un, ak)
47+
py.get_figure('PlotlyImageTest', str(file_id))
48+
49+
@attr('slow')
50+
def test_get_figure_with_url(self):
51+
un = 'PlotlyImageTest'
52+
ak = '786r5mecv0'
53+
url = "https://plot.ly/~PlotlyImageTest/2/"
54+
py.sign_in(un, ak)
55+
py.get_figure(url)
56+
57+
def test_get_figure_invalid_1(self):
58+
un = 'PlotlyImageTest'
59+
ak = '786r5mecv0'
60+
url = "https://plot.ly/~PlotlyImageTest/a/"
61+
py.sign_in(un, ak)
62+
with self.assertRaises(exceptions.PlotlyError):
63+
py.get_figure(url)
64+
65+
@attr('slow')
66+
def test_get_figure_invalid_2(self):
67+
un = 'PlotlyImageTest'
68+
ak = '786r5mecv0'
69+
url = "https://plot.ly/~PlotlyImageTest/-1/"
70+
py.sign_in(un, ak)
71+
with self.assertRaises(exceptions.PlotlyError):
72+
py.get_figure(url)
73+
74+
@attr('slow')
75+
def test_get_figure_does_not_exist(self):
76+
un = 'PlotlyImageTest'
77+
ak = '786r5mecv0'
78+
url = "https://plot.ly/~PlotlyImageTest/1000000000/"
79+
py.sign_in(un, ak)
80+
with self.assertRaises(exceptions.PlotlyError):
81+
py.get_figure(url)
82+
83+
@attr('slow')
84+
def test_get_figure_raw(self):
85+
un = 'PlotlyImageTest'
86+
ak = '786r5mecv0'
87+
file_id = 2
88+
py.sign_in(un, ak)
89+
py.get_figure('PlotlyImageTest', str(file_id), raw=True)
90+
91+
11392
class TestBytesVStrings(TestCase):
11493

11594
@skipIf(not six.PY3, 'Decoding and missing escapes only seen in PY3')
@@ -118,6 +97,4 @@ def test_proper_escaping(self):
11897
ak = '786r5mecv0'
11998
url = "https://plot.ly/~PlotlyImageTest/91/"
12099
py.sign_in(un, ak)
121-
print("getting: https://plot.ly/~PlotlyImageTest/91/")
122-
print("###########################################\n\n")
123-
fig = py.get_figure(url)
100+
py.get_figure(url)

0 commit comments

Comments
 (0)