question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

problem with image.save_as in Jupyter notebook

See original GitHub issue

Hi,

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:closed
  • Created 8 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
ITSecMediacommented, Oct 2, 2016

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.

py.image.save_as(plotly_fig, 'your_image_filename.png') 
...
TypeError                                 Traceback (most recent call last)
C:\Tools\Anaconda\envs\ETL\lib\site-packages\plotly\plotly\plotly.py in get(figure_or_data, format, width, height, scale)
    702                         'json' in headers['content-type']):
--> 703                     return_data = json.loads(res.content)
    704                 else:

C:\Tools\Anaconda\envs\ETL\lib\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'
0reactions
jonmmeasecommented, Sep 22, 2018

Update: Fully free/offline/open source static image export is now possible using the orca integration introduced in version 3.2

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found