Plots pane has problems saving images generated by Plotly
See original GitHub issueIssue Report Checklist
- Searched the issues page for similar reports
- Read the relevant sections of the Spyder Troubleshooting Guide and followed its advice
- Reproduced the issue after updating with
conda update spyder
(orpip
, if not using Anaconda) - Could not reproduce inside
jupyter qtconsole
(if console-related) - Tried basic troubleshooting (if a bug/error)
- Restarted Spyder
- Reset preferences with
spyder --reset
- Reinstalled the latest version of Anaconda
- Tried the other applicable steps from the Troubleshooting Guide
- Completed the Problem Description, Steps to Reproduce and Version sections below
Problem Description
The newly add feature: plots has problems with saving the plotted image produced by Plotly.
When using the Save Image As… button, the saved image will have the default size of 700x450 px. This cannot be changed even if the size is specified otherwise in plotly API.
If the image is saved by Plotly itself, the image will have a correct size (ex. 800x600 px).
What steps reproduce the problem?
- plot anything in Plotly.
- specify the image size.
- save the image using “Save Image As…” button in Spyder.
What is the expected output? What do you see instead?
The saved image will have a default size (i.e. 700x450) which cannot be changed.
Paste Traceback/Error Below (if applicable)
PASTE TRACEBACK HERE
Versions
- Spyder version: 4.0.0
- Python version: 3.7.3
- Plotly version: 4.1.1
Dependencies
Reproducing the problem:
import plotly.graph_objects as go
import os
script_path = os.path.dirname(os.path.realpath(__file__))
animals=['giraffes', 'orangutans', 'monkeys']
fig = go.Figure([go.Bar(x=animals, y=[20, 14, 23])])
fig.update_layout(height = 600,
width = 800,)
fig.show()
fig.write_image(script_path + '/fig.png')
Issue Analytics
- State:
- Created 4 years ago
- Comments:12 (10 by maintainers)
Top Results From Across the Web
Static image export in Python - Plotly
Plotly allows you to save static images of your plots. Save the image to your local computer, or embed it inside your Jupyter...
Read more >Not able to save plotly plots using to_image or write_image
This makes my VSCode go bananas, the terminal hangs and the program stops then and there. Everything works fine if I remove just...
Read more >Problem with Plots or Graphics Device in the RStudio IDE
This error indicates that the margins of the particular plot are very large while the region allocated for the plot is too small....
Read more >Plotly — Panel v0.14.2
The Plotly pane renders Plotly plots inside a panel. It optimizes the plot rendering by using binary serialization for any array data found...
Read more >2 Saving Plots | Using R Plots in Documents
One strategy we could take to size our plots is to adjust the Plots pane. This allows for us to see how the...
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
This is pretty nice @jnsebgosselin! I think we should add this to
spyder-kernels
, like this:You need to add some lines similar to these ones:
https://github.com/spyder-ide/spyder-kernels/blob/2c5b36cdb797b8aba77bc406ca96f5e079c4aaca/spyder_kernels/console/start.py#L125-L127
to register the renderer at startup.
Then you need to create a method in our kernel, similar to this one
https://github.com/spyder-ide/spyder-kernels/blob/2c5b36cdb797b8aba77bc406ca96f5e079c4aaca/spyder_kernels/console/kernel.py#L520-L531
with the code you posted above to do the actual job (but inside a try/except to account for the possibility of not having Plotly installed).
I don’t know, I’ll take a look and report back.