|
6 | 6 |
|
7 | 7 | from nose.tools import raises |
8 | 8 | from unittest import TestCase |
| 9 | +import json |
9 | 10 |
|
10 | 11 | import plotly |
11 | 12 |
|
12 | 13 | # TODO: matplotlib-build-wip |
13 | 14 | from plotly.tools import _matplotlylib_imported |
| 15 | + |
14 | 16 | if _matplotlylib_imported: |
15 | 17 | import matplotlib |
16 | | - |
17 | 18 | # Force matplotlib to not use any Xwindows backend. |
18 | 19 | matplotlib.use('Agg') |
19 | 20 | import matplotlib.pyplot as plt |
20 | 21 |
|
| 22 | + |
21 | 23 | # Generate matplotlib plot for tests |
22 | 24 | fig = plt.figure() |
23 | 25 |
|
@@ -59,24 +61,11 @@ def _read_html(self, file_url): |
59 | 61 | return f.read() |
60 | 62 |
|
61 | 63 | def test_default_mpl_plot_generates_expected_html(self): |
62 | | - data_json = ('[{"name": "_line0", "yaxis": "y1", "marker": {"color":' + |
63 | | - ' "#0000FF", "opacity": 1, "line": {"color": "#000000",' + |
64 | | - ' "width": 0.5}, "symbol": "dot", "size": 6.0}, "mode":' + |
65 | | - ' "markers", "xaxis": "x1", "y": [100.0, 200.0, 300.0],' + |
66 | | - ' "x": [10.0, 20.0, 30.0], "type": "scatter"}]') |
67 | | - layout_json = ('{"autosize": false, "width": 640, "showlegend": ' + |
68 | | - 'false, "xaxis1": {"tickfont": {"size": 12.0}, ' + |
69 | | - '"domain": [0.0, 1.0], "ticks": "inside", "showgrid":' + |
70 | | - ' false, "range": [10.0, 30.0], "mirror": "ticks", ' + |
71 | | - '"zeroline": false, "showline": true, "nticks": 5, ' + |
72 | | - '"type": "linear", "anchor": "y1", "side": "bottom"},' + |
73 | | - ' "height": 480, "yaxis1": {"tickfont": ' + |
74 | | - '{"size": 12.0}, "domain": [0.0, 1.0], "ticks": ' + |
75 | | - '"inside", "showgrid": false, "range": [100.0, 300.0]' + |
76 | | - ', "mirror": "ticks", "zeroline": false, "showline": ' + |
77 | | - 'true, "nticks": 5, "type": "linear", "anchor": "x1",' + |
78 | | - ' "side": "left"}, "hovermode": "closest", "margin":' + |
79 | | - ' {"b": 47, "r": 63, "pad": 0, "t": 47, "l": 80}}') |
| 64 | + figure = plotly.tools.mpl_to_plotly(fig) |
| 65 | + data = figure['data'] |
| 66 | + layout = figure['layout'] |
| 67 | + data_json = json.dumps(data, cls=plotly.utils.PlotlyJSONEncoder) |
| 68 | + layout_json = json.dumps(layout, cls=plotly.utils.PlotlyJSONEncoder) |
80 | 69 | html = self._read_html(plotly.offline.plot_mpl(fig)) |
81 | 70 |
|
82 | 71 | # just make sure a few of the parts are in here |
|
0 commit comments