Add simple matplotlib bar plots per run
As well as a flag to turn plotting on
This commit is contained in:
90062
copycat.log
90062
copycat.log
File diff suppressed because it is too large
Load Diff
@ -1 +1,2 @@
|
|||||||
from .copycat import Copycat, Reporter # noqa
|
from .copycat import Copycat, Reporter # noqa
|
||||||
|
from .plot import plot_answers
|
||||||
|
|||||||
18
copycat/plot.py
Normal file
18
copycat/plot.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import matplotlib.pyplot as plt; plt.rcdefaults()
|
||||||
|
import numpy as np
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
|
|
||||||
|
def plot_answers(answers):
|
||||||
|
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]
|
||||||
|
|
||||||
|
y_pos = np.arange(len(objects))
|
||||||
|
|
||||||
|
plt.bar(y_pos, yvalues, align='center', alpha=0.5)
|
||||||
|
plt.xticks(y_pos, objects)
|
||||||
|
plt.ylabel('Count')
|
||||||
|
plt.title('Answers')
|
||||||
|
plt.show()
|
||||||
|
|
||||||
5
main.py
5
main.py
@ -35,7 +35,7 @@ final temperature of the workspace; lower means "more elegant".
|
|||||||
import argparse
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from copycat import Copycat, Reporter
|
from copycat import Copycat, Reporter, plot_answers
|
||||||
|
|
||||||
|
|
||||||
class SimpleReporter(Reporter):
|
class SimpleReporter(Reporter):
|
||||||
@ -55,6 +55,7 @@ def main():
|
|||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument('--seed', type=int, default=None, help='Provide a deterministic seed for the RNG.')
|
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('--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('initial', type=str, help='A...')
|
parser.add_argument('initial', type=str, help='A...')
|
||||||
parser.add_argument('modified', type=str, help='...is to B...')
|
parser.add_argument('modified', type=str, help='...is to B...')
|
||||||
parser.add_argument('target', type=str, help='...as C is to... what?')
|
parser.add_argument('target', type=str, help='...as C is to... what?')
|
||||||
@ -66,6 +67,8 @@ def main():
|
|||||||
for answer, d in sorted(iter(answers.items()), key=lambda kv: kv[1]['avgtemp']):
|
for answer, d in sorted(iter(answers.items()), key=lambda kv: kv[1]['avgtemp']):
|
||||||
print('%s: %d (avg time %.1f, avg temp %.1f)' % (answer, d['count'], d['avgtime'], d['avgtemp']))
|
print('%s: %d (avg time %.1f, avg temp %.1f)' % (answer, d['count'], d['avgtime'], d['avgtemp']))
|
||||||
|
|
||||||
|
if options.plot:
|
||||||
|
plot_answers(answers)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user