Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. import numpy as np
  2. from bokeh.plotting import figure, show, output_file
  3. from bokeh.models import ColumnDataSource, LabelSet
  4.  
  5. num_vars = 9
  6.  
  7. theta = np.linspace(0, 2*np.pi, num_vars, endpoint=False)
  8. # rotate theta such that the first axis is at the top
  9. theta += np.pi/2
  10.  
  11. def unit_poly_verts(theta):
  12. """Return vertices of polygon for subplot axes.
  13. This polygon is circumscribed by a unit circle centered at (0.5, 0.5)
  14. """
  15. x0, y0, r = [0.5] * 3
  16. verts = [(r*np.cos(t) + x0, r*np.sin(t) + y0) for t in theta]
  17. return verts
  18.  
  19. def radar_patch(r, theta):
  20. yt = (r + 0.01) * np.sin(theta) + 0.5
  21. xt = (r + 0.01) * np.cos(theta) + 0.5
  22. return xt, yt
  23.  
  24. verts = unit_poly_verts(theta)
  25. x = [v[0] for v in verts]
  26. y = [v[1] for v in verts]
  27.  
  28. p = figure(title="Radar")
  29. text = ['Sulfate', 'Nitrate', 'EC', 'OC1', 'OC2', 'OC3', 'OP', 'CO', 'O3']
  30. source = ColumnDataSource({'x':x+ [0.5],'y':y+ [1],'text':text})
  31.  
  32. p.line(x="x", y="y", source=source)
  33.  
  34. labels = LabelSet(x="x",y="y",text="text",source=source)
  35.  
  36. p.add_layout(labels)
  37.  
  38. # example factor:
  39. f1 = np.array([0.88, 0.01, 0.03, 0.03, 0.00, 0.06, 0.01, 0.00, 0.00]) * 0.5
  40. f2 = np.array([0.07, 0.95, 0.04, 0.05, 0.00, 0.02, 0.01, 0.00, 0.00]) * 0.5
  41. f3 = np.array([0.01, 0.02, 0.85, 0.19, 0.05, 0.10, 0.00, 0.00, 0.00]) * 0.5
  42. f4 = np.array([0.02, 0.01, 0.07, 0.01, 0.21, 0.12, 0.98, 0.00, 0.00]) * 0.5
  43. f5 = np.array([0.01, 0.01, 0.02, 0.71, 0.74, 0.70, 0.00, 0.00, 0.00]) * 0.5
  44. #xt = np.array(x)
  45. flist = [f1,f2,f3,f4,f5]
  46. colors = ['blue','green','red', 'orange','purple']
  47. for i in range(len(flist)):
  48. xt, yt = radar_patch(flist[i], theta)
  49. p.patch(x=xt, y=yt, fill_alpha=0.15, fill_color=colors[i])
  50. show(p)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement