spyder icon indicating copy to clipboard operation
spyder copied to clipboard

Showing plots from plotly

Open CarlAndersson opened this issue 11 months ago • 5 comments

Issue Report Checklist

  • [x] Searched the issues page for similar reports
  • [x] Read the relevant sections of the Spyder Troubleshooting Guide and followed its advice
  • [x] Reproduced the issue after updating with conda update spyder (or pip, if not using Anaconda)
  • [x] Could not reproduce inside jupyter qtconsole (if console-related)
  • [x] Tried basic troubleshooting (if a bug/error)
    • [x] Restarted Spyder
    • [x] Reset preferences with spyder --reset
    • [x] Reinstalled the latest version of Anaconda
    • [x] Tried the other applicable steps from the Troubleshooting Guide
  • [x] Completed the Problem Description, Steps to Reproduce and Version sections below

Problem Description

I'm trying to use spyder with the plotly plotting library, but I cannot figure out how to make the plots render in the plots pane, or inline in the command window.

What steps reproduce the problem?

  1. Create a plot using plotly
  2. Use fig.show()
import plotly.graph_objects as go
go.Figure(go.Scatter(x=[1,2], y=[1,2])).show()

What is the expected output? What do you see instead?

I would expect a plot to appear somewhere.

Versions

  • Spyder version: 5.5.3 (conda)
  • Python version: 3.12.2
  • Qt version: 5.15.8
  • PyQt version: 5.15.9
  • Operating System name/version: Windows

Dependencies

plotly

CarlAndersson avatar Mar 18 '24 14:03 CarlAndersson

If you want plotly figures for their interactivity I think you need to use the browser renderer. Either with overriding default renderer:

import plotly.graph_objects as go
go.Figure(go.Scatter(x=[1,2], y=[1,2])).show(renderer='browser')

or set the default:

import plotly.io as pio
pio.renderers.default = "browser"

See: https://plotly.com/python/renderers/#setting-the-default-renderer

In the case of static images, I thought it was supposed to work with QtConsole/IPython/Spyder (https://plotly.com/python/renderers/#static-image-renderers). Note that this requires kaleido. For example:

import plotly.graph_objects as go
go.Figure(go.Scatter(x=[1,2], y=[1,2])).show(renderer='png')

But the console freezes for me trying to do that...

Edit: I was running spyder-kernels 2.5.0 in that env, but updating to 2.5.1 (also updated ipykernel to 6.29.3) and it works with renderer='png' and renderer='svg' - static plot shows in the plots pane.

rhkarls avatar Mar 18 '24 21:03 rhkarls