0

I have plotted the data and the legend color is different from the graph.

for row in Survey2.values.tolist():
    values = row[1:] + [row[1]]
    plt.polar(angles, values, 'o-', linewidth=0.5, label=row[0])
    plt.fill(angles, values, alpha=0.25)

    
# Representation of the spider graph
plt.legend(Survey2["createdAt"], 
            loc=4, 
            fontsize=7)
            
plt.title('PHQ-9,GAD-7 and Likert Scale over the study period', size=12, y=1.07)
plt.thetagrids(angles * 180 / np.pi, labels)
plt.figure(figsize=(10, 10))
plt.show()

Spider plot

Azhar Khan
  • 3,829
  • 11
  • 26
  • 32
Doaa A
  • 3
  • 2
  • 1
    Does this answer your question? [Show only certain items in legend Python Matplotlib](https://stackoverflow.com/questions/24680981/show-only-certain-items-in-legend-python-matplotlib) – XaC Jan 03 '23 at 12:16

1 Answers1

0

You are plotting two elements per row:

  1. plt.polar(... the points
  2. plt.fill(... the shading

So when you add your legend, you get two items per row of data: one for the points, and one for the fill. And the legend is the same colour as your plot. There's just only 3 entries for the legend, but 6 curves

You can avoid this by adding label='_nolegend_' to your plt.fill( as answered in a similar question: Show only certain items in legend Python Matplotlib

Also, if you add a label when creating the curves (with label=row[0]), why do you add new labels Survey2["createdAt"] when creating the legend? This will overwrite the ones given before

XaC
  • 432
  • 3
  • 9