The-Python-Graph-Gallery icon indicating copy to clipboard operation
The-Python-Graph-Gallery copied to clipboard

Closing radar chart with plotly go.Scatterpolar

Open leomignot opened this issue 2 months ago • 0 comments

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.

leomignot avatar Nov 26 '25 21:11 leomignot