<commit_before>#!/usr/bin/env python

import os,sys,argparse
sys.path.insert(1, os.path.join(os.path.dirname(__file__), os.pardir))
from toollib.files import ParameterParser
from toollib.group import Group,run_grouping
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
plt.ioff()
import numpy as np
from matplotlib.ticker import FormatStrFormatter
from matplotlib.dates import DateFormatter
from matplotlib.artist import setp

class PlotGroup(Group):
    def __init__(self, tup):
        super(PlotGroup, self).__init__(tup)
        self.data = {}
        for v in args.current.mapping:
            self.data[v] = []
        # if 'y' not in self.data or 'x' not in self.data:
        #     raise ValueError('Missing required mapping x or y')

    def add(self, chunks):
        for v,c in args.current.mapping.iteritems():
            self.data[v].append(chunks[c])

    def done(self):
        for geom in args.current.geom.split('+'):
            if not hasattr(self, 'plot_{0}'.format(geom)):
                raise ValueError('Invalid geometry {0} specified'.format(geom))
            obj = getattr(self, 'plot_{0}'.format(geom))()

            if args.current.label and len(self.tup) > 0:
                label = "{0}: {1}".format(args.current.label if args.current.label else '', ' '.join(self.tup))
                obj.set_label(label)
            elif args.current.label:
                obj.set_label(args.current.label)
                pass
            elif len(self.tup) > 0:
                obj.set_label(' '.join(self.tup))

    def plot_line(self):
        line, = args.ax.plot([fmt(x, args.xtype, args.xformat) for x in self.data['x']],
            [fmt(y, args.ytype, args.yformat) for y in self.data['y']],
            args.current.shape if args.current.shape else '-')
        if args.current.colour:
            line.set_color(args.current.colour)
        if args.current.size:
            setp(line, linewidth=args.current.size)
            line.set_markersize(args.current.size)
        if args.current.alpha:
            line.set_alpha(args.current.alpha)
        return line

    def plot_errorbar(self):
        err = None
        if 'ylow' in self.data and 'yhigh' in self.data:
            err = [[fmt(y, args.ytype, args.yformat) for y in self.data['ylow']], [fmt(y, args.ytype, args.yformat) for y in self.data['yhigh']]]
        elif 'ydelta' in self.data:
            err = [fmt(y, args.ytype, args.yformat) for y in self.data['ydelta']]
        else:
            raise ValueError('Missing mapping for ylow and yhigh or ydelta')
        line = args.ax.errorbar([fmt(x, args.xtype, args.xformat) for x in self.data['x']],
            [fmt(y, args.ytype, args.yformat) for y in self.data['y']],
            yerr = err, fmt = args.current.shape if args.current.shape else 'o')
        if args.current.colour:
            line.set_color(args.current.colour)
        if args.current.size:
            setp(line, linewidth=args.current.size)
            #line.set_markersize(args.current.size)
            #setp(line, elinewidth=args.current.size)
        return line

    def plot_bar(self):
        if not hasattr(args, 'baroffset'):
            args.baroffset = 0
        bars = args.ax.bar([fmt(x, args.xtype, args.xformat) + args.baroffset for x in self.data['x']],
            [fmt(y, args.ytype, args.yformat) for y in self.data['y']])

        for bar in bars:
            if args.current.colour:
                bar.set_color(args.current.colour)
            if args.current.size:
                setp(bar, width=args.current.size)
            if args.current.alpha:
                bar.set_alpha(args.current.alpha)
        args.baroffset += bars[0].get_width()
        return bars

    def plot_stackbar(self):
        y = np.array([fmt(y, args.ytype, args.yformat) for y in self.data['y']])
        bars = args.ax.bar([fmt(x, args.xtype, args.xformat) for x in self.data['x']],
            y,
            bottom = args.stackbottom if hasattr(args, 'stackbottom') else None)
        # Save the bottom position for next data
        if hasattr(args, 'stackbottom'):
            args.stackbottom += y
        else:
            args.stackbottom = y

        for bar in bars:
            if args.current.colour:
                bar.set_color(args.current.colour)
            if args.current.size:
                setp(bar, width=args.current.size)
            if args.current.alpha:
                bar.set_alpha(args.current.alpha)
        return bars

    def plot_point(self):
        if not args.current.shape:
            args.current.shape = 'o'
        return self.plot_line() # Lines and points are the same in matplotlib, shape is the only difference

    def plot_step(self):
        line = self.plot_line()
        line.set_drawstyle('steps')
        return line

    def plot_boxplot(self):
        if not hasattr(args, 'boxplotx'):
            args.boxplotx = 1
        box = args.ax.boxplot([fmt(y, args.ytype, args.yformat) for y in self.data['sample']],
            args.boxplotx)
        args.boxplotx += 1
        return box

    def plot_ribbon(self):
        if 'yy' not in self.data:
            raise ValueError('Missing mapping for yy')
        ribbon = args.ax.fill_between([fmt(x, args.xtype, args.xformat) for x in self.data['x']],
            [fmt(y, args.ytype, args.yformat) for y in self.data['y']],
            [fmt(y, args.ytype, args.yformat) for y in self.data['yy']])
        if args.current.colour:
            ribbon.set_color(args.current.colour)<commit_msg>boxplot positions<commit_after>#!/usr/bin/env python

import os,sys,argparse
sys.path.insert(1, os.path.join(os.path.dirname(__file__), os.pardir))
from toollib.files import ParameterParser
from toollib.group import Group,run_grouping
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
plt.ioff()
import numpy as np
from matplotlib.ticker import FormatStrFormatter
from matplotlib.dates import DateFormatter
from matplotlib.artist import setp

class PlotGroup(Group):
    def __init__(self, tup):
        super(PlotGroup, self).__init__(tup)
        self.data = {}
        for v in args.current.mapping:
            self.data[v] = []
        # if 'y' not in self.data or 'x' not in self.data:
        #     raise ValueError('Missing required mapping x or y')

    def add(self, chunks):
        for v,c in args.current.mapping.iteritems():
            self.data[v].append(chunks[c])

    def done(self):
        for geom in args.current.geom.split('+'):
            if not hasattr(self, 'plot_{0}'.format(geom)):
                raise ValueError('Invalid geometry {0} specified'.format(geom))
            obj = getattr(self, 'plot_{0}'.format(geom))()

            if args.current.label and len(self.tup) > 0:
                label = "{0}: {1}".format(args.current.label if args.current.label else '', ' '.join(self.tup))
                obj.set_label(label)
            elif args.current.label:
                #obj.set_label(args.current.label)
                pass
            elif len(self.tup) > 0:
                obj.set_label(' '.join(self.tup))

    def plot_line(self):
        line, = args.ax.plot([fmt(x, args.xtype, args.xformat) for x in self.data['x']],
            [fmt(y, args.ytype, args.yformat) for y in self.data['y']],
            args.current.shape if args.current.shape else '-')
        if args.current.colour:
            line.set_color(args.current.colour)
        if args.current.size:
            setp(line, linewidth=args.current.size)
            line.set_markersize(args.current.size)
        if args.current.alpha:
            line.set_alpha(args.current.alpha)
        return line

    def plot_errorbar(self):
        err = None
        if 'ylow' in self.data and 'yhigh' in self.data:
            err = [[fmt(y, args.ytype, args.yformat) for y in self.data['ylow']], [fmt(y, args.ytype, args.yformat) for y in self.data['yhigh']]]
        elif 'ydelta' in self.data:
            err = [fmt(y, args.ytype, args.yformat) for y in self.data['ydelta']]
        else:
            raise ValueError('Missing mapping for ylow and yhigh or ydelta')
        line = args.ax.errorbar([fmt(x, args.xtype, args.xformat) for x in self.data['x']],
            [fmt(y, args.ytype, args.yformat) for y in self.data['y']],
            yerr = err, fmt = args.current.shape if args.current.shape else 'o')
        if args.current.colour:
            line.set_color(args.current.colour)
        if args.current.size:
            setp(line, linewidth=args.current.size)
            #line.set_markersize(args.current.size)
            #setp(line, elinewidth=args.current.size)
        return line

    def plot_bar(self):
        if not hasattr(args, 'baroffset'):
            args.baroffset = 0
        bars = args.ax.bar([fmt(x, args.xtype, args.xformat) + args.baroffset for x in self.data['x']],
            [fmt(y, args.ytype, args.yformat) for y in self.data['y']])

        for bar in bars:
            if args.current.colour:
                bar.set_color(args.current.colour)
            if args.current.size:
                setp(bar, width=args.current.size)
            if args.current.alpha:
                bar.set_alpha(args.current.alpha)
        args.baroffset += bars[0].get_width()
        return bars

    def plot_stackbar(self):
        y = np.array([fmt(y, args.ytype, args.yformat) for y in self.data['y']])
        bars = args.ax.bar([fmt(x, args.xtype, args.xformat) for x in self.data['x']],
            y,
            bottom = args.stackbottom if hasattr(args, 'stackbottom') else None)
        # Save the bottom position for next data
        if hasattr(args, 'stackbottom'):
            args.stackbottom += y
        else:
            args.stackbottom = y

        for bar in bars:
            if args.current.colour:
                bar.set_color(args.current.colour)
            if args.current.size:
                setp(bar, width=args.current.size)
            if args.current.alpha:
                bar.set_alpha(args.current.alpha)
        return bars

    def plot_point(self):
        if not args.current.shape:
            args.current.shape = 'o'
        return self.plot_line() # Lines and points are the same in matplotlib, shape is the only difference

    def plot_step(self):
        line = self.plot_line()
        line.set_drawstyle('steps')
        return line

    def plot_boxplot(self):
        if not hasattr(args, 'boxplotx'):
            args.boxplotx = 1
        box = args.ax.boxplot([fmt(y, args.ytype, args.yformat) for y in self.data['sample']],
            positions=[args.boxplotx])
        args.boxplotx += 1
        return box

    def plot_ribbon(self):
        if 'yy' not in self.data:
            raise ValueError('Missing mapping for yy')
        ribbon = args.ax.fill_between([fmt(x, args.xtype, args.xformat) for x in self.data['x']],
            [fmt(y, args.ytype, args.yformat) for y in self.data['y']],
            [fmt(y, args.ytype, args.yformat) for y in self.data['yy']])
        if args.current.colour:
            ribbon.set_color(args.current.colour)
{'fraction_non_alphanumeric': 0.12651849185638442, 'fraction_numerical': 0.0021596328624133897, 'mean_word_length': 2.148441926345609, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '50545', 'n_tokens_mistral': 3564, 'n_tokens_neox': 3480, 'n_words': 842}