holtzy / holtzy/The-Python-Graph-Gallery
Closing radar chart with plotly go.Scatterpolar
Nobody has claimed this yet.
- Dominant language
- HTML
- Stars
- 2.2k
- Forks
- 438
- PR merge metrics
- No merged PRs in 30d
Description
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.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start from the radar chart example on page 571 and inspect how its Plotly graph-object trace supplies the r and theta values. Render the page to confirm that the final point is not connected to the first, then apply and verify a solution that closes the radar line without breaking the chart.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- plotly, python
- Domain
- data-visualization
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100