-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
mpl_to_plotly offline #386
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5c73f4c
added iplot_mpl() and plotly_takeover()
arsenovic 00b6eb2
fetch arsenovics mpl offline function pr to edit and merge master
cldougl 9981fe7
add `plot_mpl` function, docstrings, examples, tests
cldougl 6dd6ed8
- :hocho: `*kwargs*` -update docstring with keyword arguments
cldougl 2b57d3d
make offline plot_mpl test more readable and update version
cldougl 60a9025
add matplotlib attr tag to matplotlib tests
cldougl 7f6298a
add matplotlib attr tag
cldougl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,10 +5,25 @@ | |
from __future__ import absolute_import | ||
|
||
from nose.tools import raises | ||
from nose.plugins.attrib import attr | ||
|
||
from unittest import TestCase | ||
import json | ||
|
||
import plotly | ||
|
||
# TODO: matplotlib-build-wip | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we make an issue for this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 yes - on it |
||
from plotly.tools import _matplotlylib_imported | ||
|
||
if _matplotlylib_imported: | ||
import matplotlib | ||
# Force matplotlib to not use any Xwindows backend. | ||
matplotlib.use('Agg') | ||
import matplotlib.pyplot as plt | ||
|
||
|
||
PLOTLYJS = plotly.offline.offline.get_plotlyjs() | ||
|
||
|
||
class PlotlyOfflineTestCase(TestCase): | ||
def setUp(self): | ||
|
@@ -22,3 +37,54 @@ def test_iplot_works_after_you_call_init_notebook_mode(self): | |
plotly.tools._ipython_imported = True | ||
plotly.offline.init_notebook_mode() | ||
plotly.offline.iplot([{}]) | ||
|
||
@attr('matplotlib') | ||
def test_iplot_mpl_works_after_you_call_init_notebook_mode(self): | ||
# Generate matplotlib plot for tests | ||
fig = plt.figure() | ||
|
||
x = [10, 20, 30] | ||
y = [100, 200, 300] | ||
plt.plot(x, y, "o") | ||
|
||
plotly.tools._ipython_imported = True | ||
plotly.offline.init_notebook_mode() | ||
plotly.offline.iplot_mpl(fig) | ||
|
||
|
||
class PlotlyOfflineMPLTestCase(TestCase): | ||
def setUp(self): | ||
pass | ||
|
||
def _read_html(self, file_url): | ||
""" Read and return the HTML contents from a file_url in the | ||
form e.g. file:///Users/chriddyp/Repos/plotly.py/plotly-temp.html | ||
""" | ||
with open(file_url.replace('file://', '').replace(' ', '')) as f: | ||
return f.read() | ||
|
||
@attr('matplotlib') | ||
def test_default_mpl_plot_generates_expected_html(self): | ||
# Generate matplotlib plot for tests | ||
fig = plt.figure() | ||
|
||
x = [10, 20, 30] | ||
y = [100, 200, 300] | ||
plt.plot(x, y, "o") | ||
|
||
figure = plotly.tools.mpl_to_plotly(fig) | ||
data = figure['data'] | ||
layout = figure['layout'] | ||
data_json = json.dumps(data, cls=plotly.utils.PlotlyJSONEncoder) | ||
layout_json = json.dumps(layout, cls=plotly.utils.PlotlyJSONEncoder) | ||
html = self._read_html(plotly.offline.plot_mpl(fig)) | ||
|
||
# just make sure a few of the parts are in here | ||
# like PlotlyOfflineTestCase(TestCase) in test_core | ||
self.assertTrue('Plotly.newPlot' in html) # plot command is in there | ||
self.assertTrue(data_json in html) # data is in there | ||
self.assertTrue(layout_json in html) # layout is in there too | ||
self.assertTrue(PLOTLYJS in html) # and the source code | ||
# and it's an <html> doc | ||
self.assertTrue(html.startswith('<html>') and html.endswith('</html>')) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = '1.9.4' | ||
__version__ = '1.9.5' |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's this
fig
statement doing here? Is this required?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as far as I could tell-yes (there weren't any use examples in the original pr)