|
| 1 | +#!/usr/bin/python3 |
| 2 | + |
| 3 | +# Copyright 2015 Francisco Pina Martins <f.pinamartins@gmail.com> |
| 4 | +# This file is part of speedup_plotter. |
| 5 | +# speedup_plotter is free software: you can redistribute it and/or modify |
| 6 | +# it under the terms of the GNU General Public License as published by |
| 7 | +# the Free Software Foundation, either version 3 of the License, or |
| 8 | +# (at your option) any later version. |
| 9 | + |
| 10 | +# speedup_plotter is distributed in the hope that it will be useful, |
| 11 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | +# GNU General Public License for more details. |
| 14 | + |
| 15 | +# You should have received a copy of the GNU General Public License |
| 16 | +# along with speedup_plotter. If not, see <http://www.gnu.org/licenses/>. |
| 17 | + |
| 18 | +import matplotlib.pyplot as plt |
| 19 | +import numpy |
| 20 | + |
| 21 | +from speedup_plotter import data_harverster |
| 22 | + |
| 23 | + |
| 24 | +def draw_bar_plot(dataframes): |
| 25 | + """ |
| 26 | + Draws a bar plot with the different times for single vs. multiple |
| 27 | + threads implementations.""" |
| 28 | + |
| 29 | + N = len(dataframes[:, 0]) |
| 30 | + single_times = dataframes[:, 1] |
| 31 | + threaded_times = dataframes[:, 2] |
| 32 | + |
| 33 | + locs = numpy.arange(N) # the x locations for the groups |
| 34 | + |
| 35 | + width = 0.35 # the width of the bars |
| 36 | + |
| 37 | + fig, ax = plt.subplots() |
| 38 | + rects1 = ax.bar(locs, single_times, width, color='grey') |
| 39 | + |
| 40 | + rects2 = ax.bar(locs+width, threaded_times, width, color='darkgrey') |
| 41 | + |
| 42 | + # add some text for labels, title and axes ticks |
| 43 | + ax.set_ylabel('Time (s)') |
| 44 | + ax.set_title('Time to calculate clustering for each value of "K", single, ' |
| 45 | + 'vs. multiple threading') |
| 46 | + ax.set_xticks(locs+width) |
| 47 | + |
| 48 | + ax.set_xticklabels(list(map(int, dataframes[:, 0]))) |
| 49 | + |
| 50 | + ax.legend((rects1[0], rects2[0]), ('Single thread', '8 threads'), loc="upper left") |
| 51 | + |
| 52 | + ax.grid(True, zorder=0) |
| 53 | + |
| 54 | + plt.savefig(argv[1] + "_plot.svg", format="svg") |
| 55 | + |
| 56 | +if __name__ == "__main__": |
| 57 | + from sys import argv |
| 58 | + # Usage: python3 bar_plotter.py K_times.csv |
| 59 | + dataframes = data_harverster(argv[1]) |
| 60 | + draw_bar_plot(dataframes) |
0 commit comments