SNABSuite  0.x
Spiking Neural Architecture Benchmark Suite
histogram.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 # SNABSuite -- Spiking Neural Architecture Benchmark Suite
5 # Copyright (C) 2017 Christoph Jenzen
6 #
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>
19 
20 """
21 Plots a histogram of a one dimensional list
22 """
23 import argparse
24 
25 parser = argparse.ArgumentParser(description='Plot a histogram')
26 
27 # Required Parameters
28 parser.add_argument("files", metavar="files", nargs='+', help="files to plot")
29 
30 # Optional arguments
31 parser.add_argument("-s", type=str, help="Name of the simulator", default="")
32 parser.add_argument("-t", type=str, help="Title of the plot", default="")
33 parser.add_argument("-b", help="Number of bins", default='auto')
34 parser.add_argument("-n", help="Normed histogram",
35  default=False, action="store_true")
36 
37 args = parser.parse_args()
38 
39 import numpy as np
40 import matplotlib.pyplot as plt
41 import os
42 
43 from dim_labels import *
44 
45 
46 def histogram_plot(data, xlabel, title="", bins='auto', normed=False):
47  fig = plt.figure()
48  if bins is not "auto":
49  plt.hist(data, bins=int(bins), density=normed, color='black',
50  histtype="bar", rwidth=0.95)
51  else:
52  plt.hist(data, density=normed, color='black',
53  histtype="bar", rwidth=0.95)
54  plt.xlabel(xlabel)
55  if normed:
56  plt.ylabel("Probability")
57  else:
58  plt.ylabel("Frequency")
59  if not title == "":
60  plt.title(title)
61  return fig
62 
63 if not os.path.exists("images"):
64  os.mkdir("images")
65 
66 for target_file in args.files:
67  #import data
68  results = np.recfromtxt(target_file, delimiter=',', loose=True)
69  xlabel = DIM_LABELS[target_file.split(".csv")[0].split("_")[-1]]
70  if args.t is "":
71  title = target_file.split("/")[-1].split("_")[0]
72  else:
73  title = args.t
74  if args.s is not "":
75  title = title + " for " + SIMULATOR_LABELS[args.s]
76 
77  fig = histogram_plot(results, xlabel, title, bins=args.b, normed=args.n)
78  fig.savefig(target_file.split(".csv")[0] + ".pdf", format='pdf',
79  bbox_inches='tight')
def histogram_plot(data, xlabel, title="", bins='auto', normed=False)
Definition: histogram.py:46