You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Spyder IDE中显示Lets-Plot生成的图表?

在Spyder中使用Lets-Plot无法显示图表的解决方法
  • 修正导入与初始化顺序
    原代码中LetsPlot.setup_html()的调用在导入lets_plot模块之前,调整顺序并添加适配参数:

    import numpy as np
    import polars as pl
    from lets_plot import *
    LetsPlot.setup_html(inline=True)  # 用inline参数适配Spyder的HTML渲染环境
    
  • 显式调用show()方法渲染图表
    构建完图表后,手动调用show()方法强制触发渲染,而非仅返回PlotSpec对象:

    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)))
        }
    )
    
    p = ggplot(data, aes(x='rating', y='cond')) + \
        geom_point(color='dark_green', alpha=.7) 
    p.show()  # 显式执行图表显示
    
  • 检查Spyder的IPython控制台图形设置
    打开Spyder的设置(Tools > Preferences),进入IPython console > Graphics:

    • 将Backend设置为Automatic或Qt5/Qt6
    • 确保Enable HTML rendering选项已勾选

内容的提问来源于stack exchange,提问作者Ramakrishna S

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.05 03:59:54