def plot_cpu(*, reports, filename): """Read reports and plot the CPU""" fig = plt.figure() ax = fig.add_axes((0.1, 0.2, 0.8, 0.7)) ax.set_ylabel("% of CPU utilized") ax.set_xlabel("Seconds from start of run") ax.spines['right'].set_color('none') ax.spines['top'].set_color('none') ax.xaxis.set_ticks_position('bottom') ax.yaxis.set_ticks_position('left') ax.set_ylim(ymin=0, ymax=400) ymax = 100 lines = [] legends = [] for report in reports: r = BulkReport(report) xyvals = r.cpu_track() # Extract timestamps and convert to seconds from beginning of run xvals = [xy[0] for xy in xyvals] xmin = min(xvals) xvals = [(x - xmin).total_seconds() for x in xvals] # Extract CPU% and find max val yvals = [xy[1] for xy in xyvals] ymax = max([ymax] + yvals) # Plot and retain handle line, = plt.plot(xvals, yvals, label='report') lines.append(line) ax.legend(handles=lines) # draw legends ax.set_ylim(ymin=0, ymax=math.ceil(ymax / 100) * 100) # set ymax plt.savefig(filename, format='pdf')