problem with image.save_as in Jupyter notebook
See original GitHub issueHi,
first of all, thanks for releasing your incredible work. I just downloaded and start using plot.ly this morning. I encountered a problem when trying to save a figure as a stand-alone file. The following code is run in Jupyter notebook.
import plotly
plotly.__version__
'1.9.0'
import plotly.plotly as py
fig = {'data': [{'x': [1, 2, 3], 'y': [3, 1, 5], 'type': 'bar'}]}
py.image.save_as(fig, 'test.png')
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/usr/local/lib/python3.5/site-packages/plotly/plotly/plotly.py in get(figure_or_data, format, width, height, scale)
675 'json' in headers['content-type']):
--> 676 return_data = json.loads(res.content)
677 else:
/usr/local/Cellar/python3/3.5.0/Frameworks/Python.framework/Versions/3.5/lib/python3.5/json/__init__.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
311 raise TypeError('the JSON object must be str, not {!r}'.format(
--> 312 s.__class__.__name__))
313 if s.startswith(u'\ufeff'):
TypeError: the JSON object must be str, not 'bytes'
During handling of the above exception, another exception occurred:
PlotlyError Traceback (most recent call last)
<ipython-input-4-313e94b790ad> in <module>()
1 import plotly.plotly as py
2 fig = {'data': [{'x': [1, 2, 3], 'y': [3, 1, 5], 'type': 'bar'}]}
----> 3 py.image.save_as(fig, 'test.png')
/usr/local/lib/python3.5/site-packages/plotly/plotly/plotly.py in save_as(cls, figure_or_data, filename, format, width, height, scale)
758 filename += '.' + format
759
--> 760 img = cls.get(figure_or_data, format, width, height, scale)
761
762 f = open(filename, 'wb')
/usr/local/lib/python3.5/site-packages/plotly/plotly/plotly.py in get(figure_or_data, format, width, height, scale)
678 return_data = {'error': res.content}
679 except:
--> 680 raise exceptions.PlotlyError("The response "
681 "from plotly could "
682 "not be translated.")
PlotlyError: The response from plotly could not be translated.
Best regards, Flavien.
Issue Analytics
- State:
- Created 8 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
save figure to .pdf after displaying in python notebook
1 Answer 1 ... Reposting as an answer: You can't save the PDF directly from your browser, because the browser and JS code...
Read more >Saving plots - Problem Solving with Python
Matplotlib plots can be saved as image files using the plt.savefig() function. ... import matplotlib.pyplot as plt # if using a Jupyter notebook, ......
Read more >How to save a Matplotlib chart as an image with 1 click
Jupyter Notebooks Tutorial: How to save a Matplotlib chart as an image with 1 ... An error occurred while retrieving sharing information.
Read more >Export images from Jupyter Notebook using a single ... - Medium
The problem ; Option 1: Saving figures programmatically (e.g. fig.savefig for matplotlib) ; Option 2: Right click on image and “Save Image As”...
Read more >Jupyter Notebook Quick Guide
3) Next, you will type “jupyter notebook” (all lower case) to start the notebook. A lot of text will scroll by, including some...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Would be nice if there is a fix to save at last a standard png in the non-commercial “offline” edition. Just noticed this ugly bug in my jupyter notbook.
Update: Fully free/offline/open source static image export is now possible using the orca integration introduced in version 3.2