jhylands

graph.py

Apr 9th, 2014
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.88 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # a bar plot with errorbars
  3. import os
  4. os.environ['MPLCONFIGDIR'] = '/tmp/'
  5. import numpy as np
  6. import matplotlib
  7. matplotlib.use('Agg')
  8. import pylab
  9. import matplotlib.pyplot as plt
  10. import sys
  11. #get the input string and split it into X-axis labels, values, error bars
  12. input =[sys.argv[1].split('Z')]
  13. #split the X-axis labels element into an array of those labels
  14. XLabels = input[0][0].split('Y')
  15. #get a list of the siries colours
  16. COL = input[0][1].split('Y')
  17. #split the means up into siries
  18. SeriesV = input[0][2].split('Y')
  19. #split the error bars up into siries
  20. SeriesE = input[0][3].split('Y')
  21. #Error bar color
  22. ErrCol = input[0][4]
  23. #Ylabel
  24. YLabel =input[0][5]
  25. Means = [x for x in range(0,len(SeriesV))]
  26. for index in range(len(Means)):
  27.     Means[index] = SeriesV[index].split('X')
  28.     Means[index] = [float(x) for x in Means[index]]
  29. Std = [x for x in range(0,len(SeriesE))]
  30. for index in range(len(Std)):
  31.     Std[index] = SeriesE[index].split('X')
  32.     Std[index] = [float(x) for x in Std[index]]
  33. #number of bars for each series
  34. N = len(Std)
  35. #array of the error bars
  36. ind = np.arange(N)  # the x locations for the groups
  37. width = 0.3       # the width of the bars
  38. fig, ax = plt.subplots()
  39. rects = [0 for x in xrange(len(Means))]
  40. for index in range(len(Means)):
  41.     print (index)
  42.     wid = width*(index)
  43.     print(wid)
  44. #   rects[index] = ax.bar(ind + wid , Means[index], width, yerr=Std[index])
  45.     rects[index] = ax.bar(ind + wid , Means[index], width, color=("#" + COL[index]), yerr=Std[index],error_kw=dict(ecolor=("#" + ErrCol),lw=2,capsize=5,capthick=2))
  46. # add some lables
  47. ax.set_ylabel(YLabel)
  48. #ax.set_title('Scores by group and gender')
  49. ax.set_xticks(ind+width)
  50. #array of X axis lables
  51. ax.set_xticklabels( XLabels )
  52. ax.set_xlabel('Question')
  53. #legend lables
  54. #ax.legend( (rects[0][0], rects[1][0], rects[2][0]), ('woMen', 'men', 'Unspecified') )
  55. #save to tempery file
  56. print('Hello');
  57. plt.savefig('temp.png')
  58. #plt.show()
  59. print('hello');
Advertisement
Add Comment
Please, Sign In to add comment