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

Python脚本无法显示Plotly Go极坐标图求助

解决Plotly Scatterpolar图表无法显示的问题

第一步:修复脚本的基础错误

你的代码里使用了go.Figure和go.Scatterpolar但没有导入plotly的graph_objects模块,这是核心问题之一。先在脚本开头添加导入语句:

import plotly.graph_objects as go

第二步:根据运行环境选择正确的渲染方式

  • 本地带GUI的环境(桌面终端/IDE):确保安装必要依赖,执行pip3 install plotly kaleido,之后直接用fig.show()即可,默认会在浏览器或IDE内置窗口显示图表。
  • 无GUI的服务器/远程终端:无法弹出窗口,直接将图表保存为文件,把fig.show()替换成:
    fig.write_image("polar_plot.png")
    
    执行后当前目录会生成polar_plot.png文件,可下载查看。
  • 强制指定渲染器:如果仍无显示,试试强制用浏览器打开:
    fig.show(renderer="browser")
    
    若在Jupyter环境,改用renderer="notebook"。

验证修正后的完整脚本

import plotly.graph_objects as go

categories = ['First','Second','Fourth',
              'Fifth']

fig = go.Figure()
fig.add_trace(go.Scatterpolar(
      r=[38,
         44,
         25,
         11],
      theta=categories,
      fill='toself',
      name='testingonly'
))

fig.update_layout(
  polar=dict(
    radialaxis=dict(
      visible=True,
      range=[-100, 100]
    )),
  showlegend=True
)

# 根据环境选择一种方式
fig.show()  # 本地GUI环境
# fig.write_image("polar_plot.png")  # 无GUI环境
# fig.show(renderer="browser")  # 强制浏览器打开

内容的提问来源于stack exchange,提问作者just want to learn

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.11 00:31:04