Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Plotting a Radar drawing with matplotlib not working correctly

I found this resource:

https://towardsdatascience.com/how-to-make-stunning-radar-charts-with-python-implemented-in-matplotlib-and-plotly-91e21801d8ca

And I am trying to create my own version where I will analyze emotions for a free text survey. Instead of 5 categories, I will have 7 emotions:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

import numpy as np
import matplotlib.pyplot as plt


categories = ['Joy', 'Fear', 'Anger', 'Sadness', 'Disgust', 'Shame','Guilt']

q1 = [4, 4, 5, 4, 3, 7, 10]
q2 = [5, 5, 4, 5, 2,9,2]
q3 = [3, 4, 5, 3, 5,10,2]
q4 = [3, 4, 5, 3, 5,8,8]

label_loc = np.linspace(start=0, stop=2 * np.pi, num=len(q1))

plt.figure(figsize=(8, 8))
plt.subplot(polar=True)
plt.plot(label_loc, q1, label='q 1')
plt.plot(label_loc, q2, label='q 2')
plt.plot(label_loc, q3, label='q 3')
plt.plot(label_loc, q4, label='q 4')
plt.title('Answer to Question 1 - Emotion Analysis', size=20)
lines, labels = plt.thetagrids(np.degrees(label_loc), labels=categories)
plt.legend()
plt.show()

However the Joy and Guilt emotions are overlapping in the drawing.
enter image description here

What am I missing here?

>Solution :

I don’t think the original source code is correct. This produces the desired output:

enter image description here

import numpy as np
import matplotlib.pyplot as plt

categories = ['Joy', 'Fear', 'Anger', 'Sadness', 'Disgust', 'Shame','Guilt']

q1 = [4, 4, 5, 4, 3, 7, 10]
q2 = [5, 5, 4, 5, 2, 9, 2]
q3 = [3, 4, 5, 3, 5, 10, 2]
q4 = [3, 4, 5, 3, 5, 8, 8]

label_loc = np.linspace(start=0, stop=2*np.pi, num=len(q1)+1)

plt.figure(figsize=(8, 8))
plt.subplot(polar=True)
for q in [q1, q2, q3, q4]:
    plt.plot(label_loc, np.r_[q, q[0]], label='q 1')
plt.title('Answer to Question 1 - Emotion Analysis', size=20)
lines, labels = plt.thetagrids(np.degrees(label_loc), labels=categories)
plt.legend()
plt.show()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading