diff options
Diffstat (limited to 'lib/python/toys/chart.py')
-rw-r--r-- | lib/python/toys/chart.py | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/python/toys/chart.py b/lib/python/toys/chart.py index 7f78123..9a02a79 100644 --- a/lib/python/toys/chart.py +++ b/lib/python/toys/chart.py @@ -5,6 +5,8 @@ Works best with data sets prepared using toys.collect ''' import hashlib +import matplotlib +matplotlib.use('Agg') import matplotlib.pyplot as plt import toys.collect as collect @@ -66,8 +68,14 @@ def stacked_barchart(things, filename, title=None, xlabel=None, ylabel=None): plt.close() def piechart(things, filename, title=None): - labels = sorted(things.keys()) - counts = [ things[l] for l in labels ] + labels = None + if isinstance(things, dict): + labels = sorted(things.keys()) + counts = [ things[l] for l in labels ] + else: + labels = [ t[0] for t in things ] + counts = [ t[1] for t in things ] + colours = [ get_colour(l) for l in labels ] wedges, texts = plt.pie(counts, colors=colours, startangle=90) |