Skip to content

Instantly share code, notes, and snippets.

@jamescalam
Created September 11, 2019 08:03
Show Gist options
  • Save jamescalam/ddaeffd71e4c64b2a2b3a9279b4b7ede to your computer and use it in GitHub Desktop.
Save jamescalam/ddaeffd71e4c64b2a2b3a9279b4b7ede to your computer and use it in GitHub Desktop.
Example math behind creating a radar plot using continuous data split in several categories.
import numpy as np
import matplotlib.pyplot as plt
def xy(a, b, c, d, n):
v = [a, b, c, d]
r = (np.average(v)-np.min(v))/(np.max(v)-np.min(v))
x = r*np.cos((np.pi/3)*n)
y = r*np.sin((np.pi/3)*n)
return x, y
inputs = [[2056301.8, 8177980, 2710877.4, 1201452.32],
[1450601.21, 3114586.72, 1034670, 801342.4],
[14, 34, 12, 2], [0.09, 0.34, 0.16, 0.22],
[451.26, 1451, 240.8, 65.51],
[5, 9, 4, 6]]
x = []
y = []
for n, items in enumerate(inputs):
x_, y_ = xy(items[0], items[1], items[2], items[3], n)
x.append(x_)
y.append(y_)
plt.figure(figsize=(8, 8))
plt.scatter(x, y, color='k')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment