Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2b57d3d

Browse files
committed
make offline plot_mpl test more readable and update version
1 parent 6dd6ed8 commit 2b57d3d

File tree

3 files changed

+12
-23
lines changed

3 files changed

+12
-23
lines changed

plotly/offline/offline.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ def plot_mpl(mpl_fig, resize=False, strip_style=False,
319319
Convert a matplotlib figure to a Plotly graph stored locally as HTML.
320320
321321
For more information on converting matplotlib visualizations to plotly
322-
graphs, call help(plotly.plot_mpl)
322+
graphs, call help(plotly.tools.mpl_to_plotly)
323323
324324
For more information on creating plotly charts locally as an HTML document
325325
or string, call help(plotly.offline.plot)
@@ -387,7 +387,7 @@ def iplot_mpl(mpl_fig, resize=False, strip_style=False,
387387
notebook without connecting to an external server.
388388
389389
To save the chart to Plotly Cloud or Plotly Enterprise, use
390-
`plotly.tools.mpl_to_plotly`.
390+
`plotly.plotly.plot_mpl`.
391391
392392
For more information on converting matplotlib visualizations to plotly
393393
graphs call `help(plotly.tools.mpl_to_plotly)`
@@ -453,7 +453,7 @@ def enable_mpl_offline(resize=False, strip_style=False,
453453
import matplotlib.pyplot as plt
454454
455455
init_notebook_mode()
456-
plotly_takeover()
456+
enable_mpl_offline()
457457
458458
fig = plt.figure()
459459
x = [10, 15, 20, 25, 30]

plotly/tests/test_optional/test_offline/test_offline.py

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,20 @@
66

77
from nose.tools import raises
88
from unittest import TestCase
9+
import json
910

1011
import plotly
1112

1213
# TODO: matplotlib-build-wip
1314
from plotly.tools import _matplotlylib_imported
15+
1416
if _matplotlylib_imported:
1517
import matplotlib
16-
1718
# Force matplotlib to not use any Xwindows backend.
1819
matplotlib.use('Agg')
1920
import matplotlib.pyplot as plt
2021

22+
2123
# Generate matplotlib plot for tests
2224
fig = plt.figure()
2325

@@ -59,24 +61,11 @@ def _read_html(self, file_url):
5961
return f.read()
6062

6163
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)
8069
html = self._read_html(plotly.offline.plot_mpl(fig))
8170

8271
# just make sure a few of the parts are in here

plotly/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '1.9.4'
1+
__version__ = '1.9.5'

0 commit comments

Comments
 (0)