plot_job_info.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. import sys
  4. if len(sys.argv) != 2:
  5. print("Wrong number of arguments.")
  6. print("Usage: " + sys.argv[0] + " <file>")
  7. sys.exit(1)
  8. t = np.genfromtxt(sys.argv[1], names=True, delimiter=',', dtype=None)
  9. MAX=25.0
  10. N = len(t['Run'])
  11. num_plots=int(np.ceil(N/MAX))
  12. ind = np.arange(int(MAX)) # the x locations for the groups
  13. width = 0.25 # the width of the bars
  14. def short_name(job_name):
  15. n = job_name.split('_')
  16. return n[1][:6] + "_" + n[2][2:] + "_" + n[4][:1] + "_" + n[3]
  17. plt.close('all')
  18. fig = plt.figure()
  19. ax=[]
  20. expid = t['Name'][0].split('_')[0]
  21. t['Name'] = map(short_name, t['Name'])
  22. for plot in range(1,num_plots+1):
  23. ax.append(fig.add_subplot(num_plots,1, plot))
  24. l1=(plot-1)*MAX
  25. l2=plot*MAX
  26. if plot == num_plots:
  27. ind = np.arange(len(t['Queue'][l1:l2]))
  28. rects1 = ax[plot-1].bar(ind, t['Queue'][l1:l2], width, color='r')
  29. rects2 = ax[plot-1].bar(ind+width, t['Run'][l1:l2], width, color='g')
  30. rects3 = ax[plot-1].bar(ind+width*2, t['Wasted'][l1:l2], width, color='b')
  31. rects4 = ax[plot-1].bar(ind+width*3, t['Failed'][l1:l2], width, color='y')
  32. # ax[plot-1].set_ylabel('hours')
  33. ax[plot-1].set_xticks(ind+width)
  34. ax[plot-1].set_xticklabels( t['Name'][l1:l2], rotation='vertical')
  35. box = ax[plot-1].get_position()
  36. ax[plot-1].set_position([box.x0, box.y0, box.width * 0.8, box.height*0.8])
  37. ax[plot-1].set_title(expid, fontsize=20, fontweight='bold')
  38. lgd = ax[plot-1].legend( (rects1[0], rects2[0], rects3[0], rects4[0]), ('Queued (h)', 'Run (h)', 'Wasted (h)', 'Failed (#)'), loc="upper left", bbox_to_anchor=(1,1) )
  39. fig.set_size_inches(14,num_plots*6)
  40. #plt.tight_layout()
  41. plt.savefig(sys.argv[1]+ '.pdf', bbox_extra_artists=(lgd,), bbox_inches='tight')
  42. #plt.savefig('foo.pdf', bbox_inches='tight')
  43. # plt.show()