<commit_before>from string import ascii_uppercase
from math import isinf, isnan
import matplotlib.pyplot as plt
import numpy as np


label_font_size = 10
axis_font_size = 8
legend_font_size = 10
line_thickness = 1.0
markers_by_chain = ['s', 'o', 'p', '^']
colours_by_experiment = [['#01AAE9', '#1B346C', '#F44B1A', '#E5C39E'],
                         ['#F6C83C', '#4C5B28', '#DB4472', '#B77F60'],
                         ['#CBB345', '#609F80', '#4B574D', '#AF420A']]


def plot(matrix, mean_line=False, starting_gen=1, miny=0.0, maxy=1.0, y_label="Score", text=False, conf=False, col=1, text_pos='bottom', save=False, matrix_2=False, starting_gen_2=1, miny_2=0.0, maxy_2=1.0, y_label_2="Score", text_2=False, conf_2=False, col_2=1):
  
  # Initialize figure
  plt.figure(1)

  # Replace NaN with None if present in the matrix
  matrix = RemoveNaN(matrix)

  if matrix_2 != False:
    matrix_2 = RemoveNaN(matrix_2)
    if mean_line == True:
      plt.subplots(figsize=(5.5, 2.5))
      ax1 = plt.subplot2grid((6,2), (0,0), rowspan=6)
    else:
      plt.subplots(figsize=(5.5, 3.0))
      ax1 = plt.subplot2grid((6,2), (0,0), rowspan=5)
  else:
    if mean_line == True:
      plt.subplots(figsize=(5.5, 2.5))
      ax1 = plt.subplot2grid((6,1), (0,0), rowspan=6)
    else:
      plt.subplots(figsize=(5.5, 3.0))
      ax1 = plt.subplot2grid((6,1), (0,0), rowspan=5)

  n = len(matrix[0])
  colours = colours_by_experiment[col-1]
  xvals = range(starting_gen, n+starting_gen)
  if conf == True:
    plt.plot(range(-1,n+2), [1.959964] * (n+3), color='gray', linestyle=':', linewidth=0.5)
    if miny < -2.0:
      plt.plot(range(-1,n+2), [-1.959964] * (n+3), color='gray', linestyle=':', linewidth=0.5)
  elif type(conf) == int:
    plt.plot(range(-1,n+2), [conf] * (n+3), color='gray', linestyle=':', linewidth=0.5)

  if mean_line == True:
    x_vals = range(starting_gen, len(matrix[0])+starting_gen)
    means, errors = MeanWithErrors(matrix)
    _, caps, _ = ax1.errorbar(x_vals, means, yerr=errors, color='k', marker='o', markersize=3.0, linestyle="-", linewidth=line_thickness, capsize=1, elinewidth=0.5)
    for cap in caps:
      cap.set_markeredgewidth(0.5)
  else:
    for i in range(0,len(matrix)):
      x_vals = range(starting_gen, len(matrix[i])+starting_gen)
      y_vals = [item for item in matrix[i]]
      plt.plot(x_vals, y_vals, color=colours[i], marker=markers_by_chain[i], markersize=5.0, markeredgecolor=colours[i], linewidth=line_thickness, label='Chain ' + ascii_uppercase[((col-1)*4)+i:((col-1)*4)+i+1])

  labels = range(starting_gen, starting_gen+n)
  plt.xlim(starting_gen-0.5, n+starting_gen-0.5)
  plt.ylim(miny, maxy)
  plt.xticks(xvals, labels, fontsize=axis_font_size)
  plt.yticks(fontsize=axis_font_size)
  plt.xlabel("Generation number", fontsize=label_font_size)
  plt.ylabel(y_label, fontsize=label_font_size)
  plt.tick_params(axis='x', which='both', bottom='off', top='off')
  if text != False:
    if text_pos == 'bottom':
      text_y = miny + (abs(miny-maxy)/15.)
    else:
      text_y = maxy - ((abs(miny-maxy)/15.)*1.45)
    plt.text(starting_gen, text_y, text, {'fontsize':8}, fontweight='bold')
  
  if matrix_2 != False:
    if mean_line == True:
      ax2 = plt.subplot2grid((6,2), (0,1), rowspan=6)
    else:
      ax2 = plt.subplot2grid((6,2), (0,1), rowspan=5)
    n = len(matrix_2[0])
    colours = colours_by_experiment[col_2-1]
    xvals = range(starting_gen_2, n+starting_gen_2)
    if conf_2 == True:
      plt.plot(range(-1,n+2), [1.959964] * (n+3), color='gray', linestyle=':', linewidth=0.5)
      if miny_2 < -2.0:
        plt.plot(range(-1,n+2), [-1.959964] * (n+3), color='gray', linestyle=':', linewidth=0.5)
    elif type(conf_2) == int:
      plt.plot(range(-1,n+2), [conf_2] * (n+3), color='gray', linestyle=':', linewidth=0.5)

    if mean_line == True:
      x_vals = range(starting_gen_2, len(matrix_2[0])+starting_gen_2)
      means, errors = MeanWithErrors(matrix_2)
      _, caps, _ = ax2.errorbar(x_vals, means, yerr=errors, marker='o', markersize=3.0, color='k', linestyle="-", linewidth=line_thickness, capsize=1, elinewidth=0.5)
      for cap in caps:
        cap.set_markeredgewidth(0.5)
    else:
      for i in range(0,len(matrix_2)):
        x_vals = range(starting_gen_2, len(matrix_2[i])+starting_gen_2)
        y_vals = [item for item in matrix_2[i]]
        plt.plot(x_vals, y_vals, color=colours[i], marker=markers_by_chain[i], markersize=5.0, markeredgecolor=colours[i], linewidth=line_thickness)

    labels = range(starting_gen_2, starting_gen_2+n)
    plt.xlim(starting_gen_2-0.5, n+starting_gen_2-0.5)
    plt.ylim(miny_2, maxy_2)
    plt.xticks(xvals, labels, fontsize=axis_font_size)
    plt.yticks(fontsize=axis_font_size)
    plt.xlabel("Generation number", fontsize=label_font_size)
    if y_label_2 != False:
      plt.ylabel(y_label_2, fontsize=label_font_size)
    if (miny == miny_2) and (maxy == maxy_2):
      ax2.set_yticklabels([])
    plt.tick_params(axis='x', which='both', bottom='off', top='off')
    if text_2 != False:
      if text_pos == 'bottom':
        text_y = miny_2 + (abs(miny_2-maxy_2)/15.)
      else:
        text_y = maxy_2 - ((abs(miny_2-maxy_2)/15.)*1.45)
      plt.text(starting_gen_2, text_y, text_2, {'fontsize':8}, fontweight='bold')

  if mean_line == False:
    if matrix_2 != False:
      ax3 = plt.subplot2grid((6,2), (5,0), colspan=2)
    else:
      ax3 = plt.subplot2grid((6,1), (5,0))
    plt.axis('off')
    handles, labels = ax1.get_legend_handles_labels()
    ax3.legend(handles, labels, loc='upper center', frameon=False, prop={'size':legend_font_size}, ncol=4, numpoints=1)

  plt.tight_layout(pad=0.2, w_pad=1.0, h_pad=0.00)

  plt.savefig(save)
  plt.clf()


def all(dataset, starting_gen=False, miny=False, maxy=False, y_label=False, text=False, conf=False, experiment=False, text_pos=False, save_location=False, save_name=False, dataset2=False, starting_gen2=False, miny2=False, maxy2=False, y_label2=False, text2=False, conf2=False, experiment2=False):
  <commit_msg>Renamed plot.all to plot.chains<commit_after>from string import ascii_uppercase
from math import isinf, isnan
import matplotlib.pyplot as plt
import numpy as np


label_font_size = 10
axis_font_size = 8
legend_font_size = 10
line_thickness = 1.0
markers_by_chain = ['s', 'o', 'p', '^']
colours_by_experiment = [['#01AAE9', '#1B346C', '#F44B1A', '#E5C39E'],
                         ['#F6C83C', '#4C5B28', '#DB4472', '#B77F60'],
                         ['#CBB345', '#609F80', '#4B574D', '#AF420A']]


def plot(matrix, mean_line=False, starting_gen=1, miny=0.0, maxy=1.0, y_label="Score", text=False, conf=False, col=1, text_pos='bottom', save=False, matrix_2=False, starting_gen_2=1, miny_2=0.0, maxy_2=1.0, y_label_2="Score", text_2=False, conf_2=False, col_2=1):
  
  # Initialize figure
  plt.figure(1)

  # Replace NaN with None if present in the matrix
  matrix = RemoveNaN(matrix)

  if matrix_2 != False:
    matrix_2 = RemoveNaN(matrix_2)
    if mean_line == True:
      plt.subplots(figsize=(5.5, 2.5))
      ax1 = plt.subplot2grid((6,2), (0,0), rowspan=6)
    else:
      plt.subplots(figsize=(5.5, 3.0))
      ax1 = plt.subplot2grid((6,2), (0,0), rowspan=5)
  else:
    if mean_line == True:
      plt.subplots(figsize=(5.5, 2.5))
      ax1 = plt.subplot2grid((6,1), (0,0), rowspan=6)
    else:
      plt.subplots(figsize=(5.5, 3.0))
      ax1 = plt.subplot2grid((6,1), (0,0), rowspan=5)

  n = len(matrix[0])
  colours = colours_by_experiment[col-1]
  xvals = range(starting_gen, n+starting_gen)
  if conf == True:
    plt.plot(range(-1,n+2), [1.959964] * (n+3), color='gray', linestyle=':', linewidth=0.5)
    if miny < -2.0:
      plt.plot(range(-1,n+2), [-1.959964] * (n+3), color='gray', linestyle=':', linewidth=0.5)
  elif type(conf) == int:
    plt.plot(range(-1,n+2), [conf] * (n+3), color='gray', linestyle=':', linewidth=0.5)

  if mean_line == True:
    x_vals = range(starting_gen, len(matrix[0])+starting_gen)
    means, errors = MeanWithErrors(matrix)
    _, caps, _ = ax1.errorbar(x_vals, means, yerr=errors, color='k', marker='o', markersize=3.0, linestyle="-", linewidth=line_thickness, capsize=1, elinewidth=0.5)
    for cap in caps:
      cap.set_markeredgewidth(0.5)
  else:
    for i in range(0,len(matrix)):
      x_vals = range(starting_gen, len(matrix[i])+starting_gen)
      y_vals = [item for item in matrix[i]]
      plt.plot(x_vals, y_vals, color=colours[i], marker=markers_by_chain[i], markersize=5.0, markeredgecolor=colours[i], linewidth=line_thickness, label='Chain ' + ascii_uppercase[((col-1)*4)+i:((col-1)*4)+i+1])

  labels = range(starting_gen, starting_gen+n)
  plt.xlim(starting_gen-0.5, n+starting_gen-0.5)
  plt.ylim(miny, maxy)
  plt.xticks(xvals, labels, fontsize=axis_font_size)
  plt.yticks(fontsize=axis_font_size)
  plt.xlabel("Generation number", fontsize=label_font_size)
  plt.ylabel(y_label, fontsize=label_font_size)
  plt.tick_params(axis='x', which='both', bottom='off', top='off')
  if text != False:
    if text_pos == 'bottom':
      text_y = miny + (abs(miny-maxy)/15.)
    else:
      text_y = maxy - ((abs(miny-maxy)/15.)*1.45)
    plt.text(starting_gen, text_y, text, {'fontsize':8}, fontweight='bold')
  
  if matrix_2 != False:
    if mean_line == True:
      ax2 = plt.subplot2grid((6,2), (0,1), rowspan=6)
    else:
      ax2 = plt.subplot2grid((6,2), (0,1), rowspan=5)
    n = len(matrix_2[0])
    colours = colours_by_experiment[col_2-1]
    xvals = range(starting_gen_2, n+starting_gen_2)
    if conf_2 == True:
      plt.plot(range(-1,n+2), [1.959964] * (n+3), color='gray', linestyle=':', linewidth=0.5)
      if miny_2 < -2.0:
        plt.plot(range(-1,n+2), [-1.959964] * (n+3), color='gray', linestyle=':', linewidth=0.5)
    elif type(conf_2) == int:
      plt.plot(range(-1,n+2), [conf_2] * (n+3), color='gray', linestyle=':', linewidth=0.5)

    if mean_line == True:
      x_vals = range(starting_gen_2, len(matrix_2[0])+starting_gen_2)
      means, errors = MeanWithErrors(matrix_2)
      _, caps, _ = ax2.errorbar(x_vals, means, yerr=errors, marker='o', markersize=3.0, color='k', linestyle="-", linewidth=line_thickness, capsize=1, elinewidth=0.5)
      for cap in caps:
        cap.set_markeredgewidth(0.5)
    else:
      for i in range(0,len(matrix_2)):
        x_vals = range(starting_gen_2, len(matrix_2[i])+starting_gen_2)
        y_vals = [item for item in matrix_2[i]]
        plt.plot(x_vals, y_vals, color=colours[i], marker=markers_by_chain[i], markersize=5.0, markeredgecolor=colours[i], linewidth=line_thickness)

    labels = range(starting_gen_2, starting_gen_2+n)
    plt.xlim(starting_gen_2-0.5, n+starting_gen_2-0.5)
    plt.ylim(miny_2, maxy_2)
    plt.xticks(xvals, labels, fontsize=axis_font_size)
    plt.yticks(fontsize=axis_font_size)
    plt.xlabel("Generation number", fontsize=label_font_size)
    if y_label_2 != False:
      plt.ylabel(y_label_2, fontsize=label_font_size)
    if (miny == miny_2) and (maxy == maxy_2):
      ax2.set_yticklabels([])
    plt.tick_params(axis='x', which='both', bottom='off', top='off')
    if text_2 != False:
      if text_pos == 'bottom':
        text_y = miny_2 + (abs(miny_2-maxy_2)/15.)
      else:
        text_y = maxy_2 - ((abs(miny_2-maxy_2)/15.)*1.45)
      plt.text(starting_gen_2, text_y, text_2, {'fontsize':8}, fontweight='bold')

  if mean_line == False:
    if matrix_2 != False:
      ax3 = plt.subplot2grid((6,2), (5,0), colspan=2)
    else:
      ax3 = plt.subplot2grid((6,1), (5,0))
    plt.axis('off')
    handles, labels = ax1.get_legend_handles_labels()
    ax3.legend(handles, labels, loc='upper center', frameon=False, prop={'size':legend_font_size}, ncol=4, numpoints=1)

  plt.tight_layout(pad=0.2, w_pad=1.0, h_pad=0.00)

  plt.savefig(save)
  plt.clf()


def chains(dataset, starting_gen=False, miny=False, maxy=False, y_label=False, text=False, conf=False, experiment=False, text_pos=False, save_location=False, save_name=False, dataset2=False, starting_gen2=False, miny2=False, maxy2=False, y_label2=False, text2=False, conf2=False, experiment2=False):
  
{'fraction_non_alphanumeric': 0.17433855851372645, 'fraction_numerical': 0.05341295512980011, 'mean_word_length': 4.1441979522184305, 'pattern_counts': {'":': 0, '<': 7, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3117475', 'n_tokens_mistral': 5113, 'n_tokens_neox': 4918, 'n_words': 859}