Adds additional plotting options
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@ -28,3 +28,6 @@ copycat.log
|
||||
|
||||
# Editors
|
||||
.*.swp
|
||||
|
||||
# Output
|
||||
output/*
|
||||
|
||||
@ -3,7 +3,7 @@ import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
|
||||
def plot_answers(answers):
|
||||
def plot_answers(answers, show=True, save=True, filename='distribution.png'):
|
||||
answers = sorted(answers.items(), key=lambda kv : kv[1]['count'])
|
||||
objects = [t[0] + ' (temp:{})'.format(t[1]['avgtemp']) for t in answers]
|
||||
yvalues = [t[1]['count'] for t in answers]
|
||||
@ -14,5 +14,7 @@ def plot_answers(answers):
|
||||
plt.xticks(y_pos, objects)
|
||||
plt.ylabel('Count')
|
||||
plt.title('Answers')
|
||||
plt.show()
|
||||
|
||||
if show:
|
||||
plt.show()
|
||||
if save:
|
||||
plt.savefig('output/{}'.format(filename))
|
||||
|
||||
3
main.py
3
main.py
@ -56,6 +56,7 @@ def main():
|
||||
parser.add_argument('--seed', type=int, default=None, help='Provide a deterministic seed for the RNG.')
|
||||
parser.add_argument('--iterations', type=int, default=1, help='Run the given case this many times.')
|
||||
parser.add_argument('--plot', action='store_true', help='Plot a bar graph of answer distribution')
|
||||
parser.add_argument('--noshow', action='store_true', help='Don\'t display bar graph at end of run')
|
||||
parser.add_argument('initial', type=str, help='A...')
|
||||
parser.add_argument('modified', type=str, help='...is to B...')
|
||||
parser.add_argument('target', type=str, help='...as C is to... what?')
|
||||
@ -68,7 +69,7 @@ def main():
|
||||
print('%s: %d (avg time %.1f, avg temp %.1f)' % (answer, d['count'], d['avgtime'], d['avgtemp']))
|
||||
|
||||
if options.plot:
|
||||
plot_answers(answers)
|
||||
plot_answers(answers, show=not options.noshow)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
0
output/.placeholder
Normal file
0
output/.placeholder
Normal file
Reference in New Issue
Block a user