Changeset 57af3f3


Ignore:
Timestamp:
Apr 26, 2022, 2:58:49 PM (2 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, ast-experimental, master, pthread-emulation, qualifiedEnum
Children:
ed49dbd
Parents:
c9136d9
Message:

Changed plotter to show all data + min,max and median.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • benchmark/plot.py

    rc9136d9 r57af3f3  
    1515import numpy
    1616import re
     17import statistics
    1718import sys
    1819
     
    4041}
    4142
    42 def plot(data, x, y, out):
     43def plot(in_data, x, y, out):
    4344        fig, ax = plt.subplots()
    4445        colors = itertools.cycle(['#0095e3','#006cb4','#69df00','#0aa000','#fb0300','#e30002','#fd8f00','#ff7f00','#8f00d6','#4b009a','#ffff00','#b13f00'])
    45         series = {}
    46         for entry in data:
    47                 if not entry[0] in series:
    48                         series[entry[0]] = {'x':[], 'y':[]}
     46        series = {} # scatter data for each individual data point
     47        groups = {} # data points for x value
     48        for entry in in_data:
     49                name = entry[0]
     50                if not name in series:
     51                        series[name] = {'x':[], 'y':[]}
     52
     53                if not name in groups:
     54                        groups[name] = {}
    4955
    5056                if x in entry[2] and y in entry[2]:
    51                         series[entry[0]]['x'].append(entry[2][x])
    52                         series[entry[0]]['y'].append(entry[2][y])
     57                        xval = entry[2][x]
     58                        yval = entry[2][y]
     59                        series[name]['x'].append(xval)
     60                        series[name]['y'].append(yval)
     61
     62                        if not xval in groups[name]:
     63                                groups[name][xval] = []
     64
     65                        groups[name][xval].append(yval)
     66
     67        lines = {} # lines from groups with min, max, median, etc.
     68        for name, data in groups.items():
     69                if not name in lines:
     70                        lines[name] = { 'x': [], 'min':[], 'max':[], 'med':[], 'avg':[] }
     71
     72                for xkey in sorted(data):
     73                        ys = data[xkey]
     74                        lines[name]['x']  .append(xkey)
     75                        lines[name]['min'].append(min(ys))
     76                        lines[name]['max'].append(max(ys))
     77                        lines[name]['med'].append(statistics.median(ys))
     78                        lines[name]['avg'].append(statistics.mean(ys))
     79
     80                print(lines[name])
    5381
    5482        for name, data in series.items():
    55                 plt.scatter(data['x'], data['y'], color=next(colors), label=name, marker='x')
     83                _col = next(colors)
     84                plt.scatter(data['x'], data['y'], color=_col, label=name, marker='x')
     85                plt.plot(lines[name]['x'], lines[name]['min'], '--', color=_col)
     86                plt.plot(lines[name]['x'], lines[name]['max'], '--', color=_col)
     87                plt.plot(lines[name]['x'], lines[name]['med'], '-', color=_col)
    5688
    5789        mx = max([max(s['x']) for s in series.values()])
Note: See TracChangeset for help on using the changeset viewer.