<commit_before>{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "code_folding": [],
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "from __future__ import (division, absolute_import, print_function, unicode_literals)\n",
    "import sys, os, bz2, re, itertools, pickle\n",
    "from copy import copy\n",
    "import numpy as np; import scipy.linalg as linalg\n",
    "import tom"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "code_folding": [
     0
    ],
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Setup the comment %%# magic\n",
    "from IPython.core.magic import register_line_cell_magic\n",
    "ip = get_ipython()\n",
    "def comment_cell_magic(line, cell):\n",
    "    \"Place a comment and execute the cell\"\n",
    "    get_ipython().run_cell(cell)\n",
    "ip.register_magic_function(comment_cell_magic, 'cell', '#')\n",
    "del comment_cell_magic, ip"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "code_folding": [
     0
    ],
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# Setup inline plotting for PhD plots (use `plt.savefig(filename, dpi=600)`)\n",
    "%matplotlib inline\n",
    "%config InlineBackend.print_figure_kwargs = {'bbox_inches':None}\n",
    "%config InlineBackend.figure_format = 'retina'\n",
    "import matplotlib as mpl\n",
    "fig_width = 412.56496/72.27; fig_height = fig_width * (np.sqrt(5)-1.0)/2.0; fig_size =  [fig_width,fig_height]\n",
    "fig_params = {'savefig.dpi': 144, 'savefig.pad_inches': 0.0, 'savefig.format': 'pdf',\n",
    "              'figure.figsize': fig_size,\n",
    "              'text.usetex': True,\n",
    "              'font.family': 'serif', 'font.serif': 'Computer Modern Roman', 'mathtext.fontset': 'cm',\n",
    "              'lines.scale_dashes': False,\n",
    "              'font.size': 9, 'axes.titlesize': 9,'axes.labelsize': 9, 'legend.fontsize': 9, 'xtick.labelsize': 8, 'ytick.labelsize': 8,\n",
    "              'xtick.top': True, 'xtick.direction': 'in', 'ytick.right': True, 'ytick.direction': 'in',\n",
    "              'axes.linewidth': 0.5, 'xtick.major.width': 0.4, 'xtick.major.size': 2, 'ytick.major.size': 2, 'ytick.major.width': 0.4, 'xtick.minor.size': 0, 'ytick.minor.size': 0,\n",
    "              'xtick.major.pad': 3, 'ytick.major.pad': 2, 'axes.labelpad': 4,\n",
    "              'legend.borderpad': 0.3, 'legend.labelspacing': 0.3,\n",
    "              'figure.subplot.bottom': 0.1\n",
    "             }\n",
    "mpl.rcParams.update(fig_params)\n",
    "import matplotlib.pyplot as plt\n",
    "import brewer2mpl\n",
    "bmap = brewer2mpl.get_map('Paired', 'qualitative', 10)\n",
    "bmap1 = brewer2mpl.get_map('set1', 'qualitative', 9)\n",
    "colors = {'red': bmap.mpl_colors[5], 'lightred': bmap.mpl_colors[4],\n",
    "          'blue': bmap.mpl_colors[1], 'lightblue': bmap.mpl_colors[0],\n",
    "          'green': bmap.mpl_colors[3], 'lightgreen': bmap.mpl_colors[2],\n",
    "          'purple': bmap.mpl_colors[9], 'lightpurple': bmap.mpl_colors[8],\n",
    "          'orange': bmap.mpl_colors[7], 'lightorange': bmap.mpl_colors[6],\n",
    "          'yellow': bmap1.mpl_colors[5], 'brown': bmap1.mpl_colors[6],\n",
    "          'pink': bmap1.mpl_colors[7], 'grey': bmap1.mpl_colors[8], 'black': 'black'}\n",
    "colorNos = ['blue', 'red', 'green', 'purple', 'orange', 'pink', 'brown', 'yellow', 'grey', 'lightblue', 'lightred', 'lightgreen', 'lightpurple']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "code_folding": [
     1,
     22,
     41
    ],
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Custom line styles\n",
    "def myStyle(lw = 1, color='black', ls='-'):\n",
    "    lw = 0.8 * lw\n",
    "    s = 0.5\n",
    "    if color in colors:\n",
    "        color = colors[color]\n",
    "    elif type(color) is int:\n",
    "        color = colors[colorNos[color]]\n",
    "    dash_capstyle = 'butt'\n",
    "    dashes = (None, None)\n",
    "    if ls == ':' or ls == 1:\n",
    "        dash_capstyle='round'\n",
    "        dashes = ((1+lw) * 0.1, (2+lw)*s)\n",
    "    elif ls == '--' or ls == 2:\n",
    "        dashes = (4*s, 2*s)\n",
    "    elif ls == ';' or ls == 3:\n",
    "        dashes = (1*s, 2*s, 4*s, 2*s)\n",
    "    elif ls == '---' or ls == 4:\n",
    "        dashes = (8*s, 1.5*s)\n",
    "    return {'lw': lw, 'dashes': dashes, 'dash_capstyle': dash_capstyle, 'color': color}\n",
    "# Hack for special legend symbol\n",
    "from matplotlib.legend_handler import HandlerTuple\n",
    "class HandlerTupleVertical(HandlerTuple):\n",
    "    def __init__(self, **kwargs):\n",
    "        HandlerTuple.__init__(self, **kwargs)\n",
    "    def create_artists(self, legend, orig_handle,\n",
    "                       xdescent, ydescent, width, height, fontsize, trans):\n",
    "        # How many lines are there.\n",
    "        numlines = len(orig_handle)\n",
    "        handler_map = legend.get_legend_handler_map()\n",
    "        # divide the vertical space where the lines will go\n",
    "        # into equal parts based on the number of lines\n",
    "        height_y = (height / numlines)\n",
    "        leglines = []\n",
    "        for i, handle in enumerate(orig_handle):\n",
    "            handler = legend.get_legend_handler(handler_map, handle)\n",
    "            legline = handler.create_artists(legend, handle, xdescent, (2*i + 1)*height_y, width, 2*height,\n",
    "                                            fontsize, trans)\n",
    "            leglines.extend(legline)\n",
    "        return leglines\n",
    "# Legend style\n",
    "def makeLegend(lines=None, labels=None, title=None, row=4):\n",
    "    ax = plt.subplot(row,3,3*row)\n",
    "    ax.tick_params(left='off', right='off', top='off', bottom='off')\n",
    "    ax.set_xticklabels([])\n",
    "    ax.set_yticklabels([])\n",
    "    for direction, lw in zip(['top', 'left', 'bottom', 'right'], BenchData.plot_info['LEGEND']['lw']):\n",
    "        ax.spines[direction].set_linewidth(lw)\n",
    "    if row == 1: ax.spines['top'].set_linewidth(0)\n",
    "    legend = plt.legend(lines, labels, loc=10, fancybox=True, title=title,\n",
    "                        handler_map = {tuple : HandlerTupleVertical()})\n",
    "    frame = legend.get_frame()\n",
    "    frame.set_facecolor('0.9')\n",
    "    frame.set_edgecolor('none')\n",
    "def finishPlot():\n",
    "    plt.tight_layout(pad=0.1)\n",
    "    plt.subplots_adjust(hspace=0, wspace=0)\n",
    "def savePlot(filename):\n",
    "    os.makedirs(research_directory + '/Results', exist_ok=True)\n",
    "    plt.savefig(research_directory + '/Results/' + filename + '.pdf', dpi=600, bbox_inches='tight', pad_inches=0)"
   ]<commit_msg>Tools.ipynb: directory fixes and legend title font size<commit_after>{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "code_folding": [],
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "from __future__ import (division, absolute_import, print_function, unicode_literals)\n",
    "import sys, os, bz2, re, itertools, pickle\n",
    "from copy import copy\n",
    "import numpy as np; import scipy.linalg as linalg\n",
    "import tom"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "code_folding": [
     0
    ],
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Setup the comment %%# magic\n",
    "from IPython.core.magic import register_line_cell_magic\n",
    "ip = get_ipython()\n",
    "def comment_cell_magic(line, cell):\n",
    "    \"Place a comment and execute the cell\"\n",
    "    get_ipython().run_cell(cell)\n",
    "ip.register_magic_function(comment_cell_magic, 'cell', '#')\n",
    "del comment_cell_magic, ip"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "code_folding": [
     0
    ],
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# Setup inline plotting for PhD plots (use `plt.savefig(filename, dpi=600)`)\n",
    "%matplotlib inline\n",
    "%config InlineBackend.print_figure_kwargs = {'bbox_inches':None}\n",
    "%config InlineBackend.figure_format = 'retina'\n",
    "import matplotlib as mpl\n",
    "fig_width = 412.56496/72.27; fig_height = fig_width * (np.sqrt(5)-1.0)/2.0; fig_size =  [fig_width,fig_height]\n",
    "fig_params = {'savefig.dpi': 144, 'savefig.pad_inches': 0.0, 'savefig.format': 'pdf',\n",
    "              'figure.figsize': fig_size,\n",
    "              'text.usetex': True,\n",
    "              'font.family': 'serif', 'font.serif': 'Computer Modern Roman', 'mathtext.fontset': 'cm',\n",
    "              'lines.scale_dashes': False,\n",
    "              'font.size': 9, 'axes.titlesize': 9,'axes.labelsize': 9, 'legend.fontsize': 9, 'xtick.labelsize': 8, 'ytick.labelsize': 8,\n",
    "              'xtick.top': True, 'xtick.direction': 'in', 'ytick.right': True, 'ytick.direction': 'in',\n",
    "              'axes.linewidth': 0.5, 'xtick.major.width': 0.4, 'xtick.major.size': 2, 'ytick.major.size': 2, 'ytick.major.width': 0.4, 'xtick.minor.size': 0, 'ytick.minor.size': 0,\n",
    "              'xtick.major.pad': 3, 'ytick.major.pad': 2, 'axes.labelpad': 4,\n",
    "              'legend.borderpad': 0.3, 'legend.labelspacing': 0.3,\n",
    "              'figure.subplot.bottom': 0.1\n",
    "             }\n",
    "mpl.rcParams.update(fig_params)\n",
    "import matplotlib.pyplot as plt\n",
    "import brewer2mpl\n",
    "bmap = brewer2mpl.get_map('Paired', 'qualitative', 10)\n",
    "bmap1 = brewer2mpl.get_map('set1', 'qualitative', 9)\n",
    "colors = {'red': bmap.mpl_colors[5], 'lightred': bmap.mpl_colors[4],\n",
    "          'blue': bmap.mpl_colors[1], 'lightblue': bmap.mpl_colors[0],\n",
    "          'green': bmap.mpl_colors[3], 'lightgreen': bmap.mpl_colors[2],\n",
    "          'purple': bmap.mpl_colors[9], 'lightpurple': bmap.mpl_colors[8],\n",
    "          'orange': bmap.mpl_colors[7], 'lightorange': bmap.mpl_colors[6],\n",
    "          'yellow': bmap1.mpl_colors[5], 'brown': bmap1.mpl_colors[6],\n",
    "          'pink': bmap1.mpl_colors[7], 'grey': bmap1.mpl_colors[8], 'black': 'black'}\n",
    "colorNos = ['blue', 'red', 'green', 'purple', 'orange', 'pink', 'brown', 'yellow', 'grey', 'lightblue', 'lightred', 'lightgreen', 'lightpurple']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "code_folding": [
     1,
     22
    ],
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Custom line styles\n",
    "def myStyle(lw = 1, color='black', ls='-'):\n",
    "    lw = 0.8 * lw\n",
    "    s = 0.5\n",
    "    if color in colors:\n",
    "        color = colors[color]\n",
    "    elif type(color) is int:\n",
    "        color = colors[colorNos[color]]\n",
    "    dash_capstyle = 'butt'\n",
    "    dashes = (None, None)\n",
    "    if ls == ':' or ls == 1:\n",
    "        dash_capstyle='round'\n",
    "        dashes = ((1+lw) * 0.1, (2+lw)*s)\n",
    "    elif ls == '--' or ls == 2:\n",
    "        dashes = (4*s, 2*s)\n",
    "    elif ls == ';' or ls == 3:\n",
    "        dashes = (1*s, 2*s, 4*s, 2*s)\n",
    "    elif ls == '---' or ls == 4:\n",
    "        dashes = (8*s, 1.5*s)\n",
    "    return {'lw': lw, 'dashes': dashes, 'dash_capstyle': dash_capstyle, 'color': color}\n",
    "# Hack for special legend symbol\n",
    "from matplotlib.legend_handler import HandlerTuple\n",
    "class HandlerTupleVertical(HandlerTuple):\n",
    "    def __init__(self, **kwargs):\n",
    "        HandlerTuple.__init__(self, **kwargs)\n",
    "    def create_artists(self, legend, orig_handle,\n",
    "                       xdescent, ydescent, width, height, fontsize, trans):\n",
    "        # How many lines are there.\n",
    "        numlines = len(orig_handle)\n",
    "        handler_map = legend.get_legend_handler_map()\n",
    "        # divide the vertical space where the lines will go\n",
    "        # into equal parts based on the number of lines\n",
    "        height_y = (height / numlines)\n",
    "        leglines = []\n",
    "        for i, handle in enumerate(orig_handle):\n",
    "            handler = legend.get_legend_handler(handler_map, handle)\n",
    "            legline = handler.create_artists(legend, handle, xdescent, (2*i + 1)*height_y, width, 2*height,\n",
    "                                            fontsize, trans)\n",
    "            leglines.extend(legline)\n",
    "        return leglines\n",
    "# Legend style\n",
    "def makeLegend(lines=None, labels=None, title=None, row=4):\n",
    "    ax = plt.subplot(row,3,3*row)\n",
    "    ax.tick_params(left='off', right='off', top='off', bottom='off')\n",
    "    ax.set_xticklabels([])\n",
    "    ax.set_yticklabels([])\n",
    "    for direction, lw in zip(['top', 'left', 'bottom', 'right'], BenchData.plot_info['LEGEND']['lw']):\n",
    "        ax.spines[direction].set_linewidth(lw)\n",
    "    if row == 1: ax.spines['top'].set_linewidth(0)\n",
    "    legend = plt.legend(lines, labels, loc=10, fancybox=True, title=title,\n",
    "                        handler_map = {tuple : HandlerTupleVertical()})\n",
    "    legend.get_title().set_fontsize('10') \n",
    "    frame = legend.get_frame()\n",
    "    frame.set_facecolor('0.9')\n",
    "    frame.set_edgecolor('none')\n",
    "def finishPlot():\n",
    "    plt.tight_layout(pad=0.1)\n",
    "    plt.subplots_adjust(hspace=0, wspace=0)\n",
    "def savePlot(filename):\n",
    "    os.makedirs(research_directory + '/results', exist_ok=True)\n",
    "    plt.savefig(research_directory + '/results/' + filename + '.pdf', dpi=600, bbox_inches='tight', pad_inches=0)"
   ]
{'fraction_non_alphanumeric': 0.201405320140532, 'fraction_numerical': 0.018498601849860186, 'mean_word_length': 2.509813789632612, 'pattern_counts': {'":': 58, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1508435', 'n_tokens_mistral': 5442, 'n_tokens_neox': 5133, 'n_words': 948}