def main(fname): data = data_by_numtyped(fname) fig,ax1 = plt.subplots() #add figsize? draw_violin(data, color='royalblue') ## add a light-colored horizontal grid ax1.yaxis.grid(True, linestyle='-', which='major', color='lightgrey', alpha=0.5) ## Shortest-path line path = shortestpath.least_sum_path(fname) plt.plot(range(1,1+len(path)), runtimes_of_path(fname, path), color='r', linestyle="--", linewidth="1") ## plot axis: runtime + num types ax1.set_axisbelow(True) ax1.set_title(fname.rsplit("/",1)[-1].rsplit(".")[0]) ax1.set_xlabel("Num. Typed Modules") ax1.set_ylabel("Runtime (ms)") plt.xticks(range(1,1+len(data)), range(0, len(data))) ## Legend # Reset y limit ymin,ymax = ax1.get_ylim() ax1.set_ylim(ymin-5, ymax) plt.figtext(0.80, 0.04, "---", color='r', weight='roman', size='x-small') plt.figtext(0.82, 0.04, "Least-sum path", color='k', weight='roman', size='x-small') plt.figtext(0.80, 0.01, '*', color='white', backgroundcolor='royalblue',weight='roman', size='medium') plt.figtext(0.82, 0.01, ' Average Value', color='black', weight='roman', size='x-small') ## Save & clear new_name = util.gen_name(fname, "violin", "png") plt.savefig(new_name) plt.clf() print("Saved figure to %s" % new_name) return
def main(fname): data = data_by_numtyped(fname) ## Add data fig, ax1 = plt.subplots() # add figsize? bp = plt.boxplot(data, notch=0, sym="+", vert=True, whis=1) plt.setp(bp["boxes"], color="black") plt.setp(bp["whiskers"], color="black") plt.setp(bp["fliers"], color="red", marker="+") ## add a light-colored horizontal grid ax1.yaxis.grid(True, linestyle="-", which="major", color="lightgrey", alpha=0.5) ## Fancier boxes for i in range(len(data)): box = bp["boxes"][i] coords = [] ## Color the boxes for j in range(0, 5): coords.append((box.get_xdata()[j], box.get_ydata()[j])) boxPolygon = Polygon(coords, facecolor="royalblue") ax1.add_patch(boxPolygon) ## Re-draw median lines med = bp["medians"][i] mx, my = [], [] for j in range(2): mx.append(med.get_xdata()[j]) my.append(med.get_ydata()[j]) plt.plot(mx, my, "black") ## Draw avg. dot plt.plot([np.average(med.get_xdata())], [np.average(data[i])], color="w", marker="*", markeredgecolor="k") ## Shortest-path line path = shortestpath.least_sum_path(fname) plt.plot(range(1, 1 + len(path)), runtimes_of_path(fname, path), color="r", linestyle="--", linewidth="1") ## plot axis: runtime + num types ax1.set_axisbelow(True) ax1.set_title(fname.rsplit("/", 1)[-1].rsplit(".")[0]) ax1.set_xlabel("Num. Typed Modules") ax1.set_ylabel("Runtime (ms)") ax1.set_xticklabels(range(0, len(path))) ## Legend # Reset y limit ymin, ymax = ax1.get_ylim() ax1.set_ylim(ymin - 5, ymax) plt.figtext(0.80, 0.04, "---", color="r", weight="roman", size="x-small") plt.figtext(0.82, 0.04, "Least-sum path", color="k", weight="roman", size="x-small") plt.figtext(0.80, 0.01, "*", color="white", backgroundcolor="royalblue", weight="roman", size="medium") plt.figtext(0.82, 0.01, " Average Value", color="black", weight="roman", size="x-small") ## Save & clear new_name = util.gen_name(fname, "boxplot", "png") plt.savefig(new_name) plt.clf() print("Saved figure to %s" % new_name) return