How to display a lets-plot plot in Spyder IDE

62 views Asked by At

I am using spyder ide and Lets-plot to generate a plot.

import numpy as np
import polars as pl
LetsPlot.setup_html()
from lets_plot import *

np.random.seed(12)
data = pl.DataFrame(
    {
    "cond":np.random.lognormal(0, 1, 400),
    "rating":np.concatenate((np.random.normal(0, 1, 200), np.random.normal(1, 1.5, 200)))
    }
)

ggplot(data, aes(x='rating', y='cond')) + \
    geom_point(color='dark_green', alpha=.7) 

Instead of showing a graph, it is simply displaying this object in ipython console.

<lets_plot.plot.core.PlotSpec at 0x2771422c100>

Any help?

1

There are 1 answers

0
Dean MacGregor On

Try doing

p=ggplot(data, aes(x='rating', y='cond')) + \
    geom_point(color='dark_green', alpha=.7) 
p.show()

I don't use spyder or letsplot so I haven't tested that but I've had similar issues with plotly on VSC and think that's what'll make it display.