Closing radar chart with plotly go.Scatterpolar

未关闭
#533 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
38/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
plotly, python

调研方向

从第 571 页的雷达图示例开始,检查其 Plotly graph-object trace 如何提供 r 和 theta 值。渲染该页面以确认最后一个点没有连接到第一个点,然后应用并验证一种在不破坏图表的情况下闭合雷达线的解决方案。

由索引模型根据 Issue 内容生成。

描述

Hi,

On this page, the radar charts created with plotly graph objects (go.Scatterpolar) do not close — the line connecting the last point back to the first is missing.

Clearly not on you; this is so typical that the official Plotly documentation does it.

The usual line_close=True method from Plotly Express does not work with Graph Objects. And fig.update_traces(connectgaps=True) does not seem to work with radar coordinates.

A possible workaround (mentioned here) is to manually close the loop by repeating the first point in r and theta:

r = df["value"].tolist() + [df["value"][0]]
theta = df["name"].tolist() + [df["name"][0]]

or

r = [*df["value"], df["value"].iloc[0]]
theta = [*df["name"], df["name"].iloc[0]]

It’s stupid, verbose and inelegant, but (on the plus size) it works.

I haven’t made a PR because this might be too niche to implement (after all, the same behavior exists on the official Plotly site), but I can submit one if needed.

PS: I'm bad at it. I might not be aware of a cleaner solution, so there could be a better way.

主要语言
HTML
星标
2.3k
派生
439
PR 合并指标
30 天内没有已合并 PR

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

holtzy/The-Python-Graph-Gallery 的其他 Issue

查看 holtzy/The-Python-Graph-Gallery 的全部 Issue

相似的 Issue

更多 Data Visualization Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。