plot_csv.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import csv
  2. from bokeh.plotting import figure, output_file, show
  3. color_pallete = [
  4. "#e41a1c",
  5. "#377eb8",
  6. "#4daf4a",
  7. "#984ea3",
  8. "#ff7f00",
  9. "#ffff33",
  10. "#a65628",
  11. "#f781bf",
  12. "#CDD460",
  13. "#265C70",
  14. "#622876",
  15. "#B37737"
  16. ]
  17. def plot_csv(filename):
  18. with open(filename, 'rb') as csvfile:
  19. rows = csv.reader(csvfile, delimiter=',')
  20. # read all rows at once
  21. matrixRows = []
  22. for row in rows:
  23. matrixRows.append(row)
  24. firstRow = matrixRows[0]
  25. numVars = len(firstRow) -1 # discount time
  26. times = []
  27. vars = []
  28. for i in range(numVars):
  29. vars.append([])
  30. for rowIdx in range(len(matrixRows)):
  31. row = matrixRows[rowIdx]
  32. times.append(float(row[0]))
  33. for varIdx in range(1, numVars):
  34. col = row[varIdx]
  35. vars[varIdx].append(float(col))
  36. plot_file = filename.replace(".csv", ".html")
  37. output_file(plot_file, title="Results")
  38. p = figure(title="Plot", x_axis_label='time', y_axis_label='', width=1300, height=900)
  39. varName = "v{0}"
  40. for i in range(numVars):
  41. p.line(x=times, y=vars[i], legend=varName.format(i), color=color_pallete[i])
  42. show(p)
  43. plot_csv('result_power_sa.csv')
  44. plot_csv('result_ENV.csv')
  45. plot_csv('result_Control_sa.csv')