<commit_before>from numpy import *
import csv
import iodata

from sys import argv

try:
    format = argv[1]
    input1 = argv[2]
    input2 = argv[3]
    output = argv[4]
except IndexError:
    print "Usage: cluster_plot.py <format> <input1> <input2> <output>"
    exit(1)

import matplotlib
if format == "png":
    matplotlib.use("Agg")
elif format == "pdf":
    matplotlib.use("PDF")
import matplotlib.pyplot as plt

r = csv.reader(open(input1), delimiter='\t')
l = []
for row in r:
    l.append([int(i) for i in row])

centroidsid = array(l[0])
mini = array(l[1])

x, mat, header, title = iodata.load_csv(input2, '\t')

clusters = {}
i = 0
for c in mini:
    try:
        clusters[c].append(mat[i])
    except KeyError:
        clusters[c] = [mat[i]]
    i += 1

colours = ['b', 'r', 'g', 'c', 'm', 'y', 'k', 'w']
lines = []
i = 0
for key in clusters.keys():
    i = i % len(colours)
    for j, time_series in enumerate(clusters[key]):
        line = plt.plot(time_series, colours[i])
        if j == 0:
            lines.append(line)
    i += 1
plt.legend(lines, ["Cluster %d" % i for i, k in enumerate(clusters.keys())])
plt.savefig(output, format=format)<commit_msg>plot fix<commit_after>from numpy import *
import csv
import iodata

from sys import argv

try:
    format = argv[1]
    input1 = argv[2]
    input2 = argv[3]
    output = argv[4]
except IndexError:
    print "Usage: cluster_plot.py <format> <input1> <input2> <output>"
    exit(1)

import matplotlib
if format == "png":
    matplotlib.use("Agg")
elif format == "pdf":
    matplotlib.use("PDF")
import matplotlib.pyplot as plt

r = csv.reader(open(input1), delimiter='\t')
l = []
for row in r:
    l.append([int(i) for i in row])

centroidsid = array(l[0])
mini = array(l[1])

x, mat, header, title = iodata.load_csv(input2, '\t')

clusters = {}
i = 0
for c in mini:
    try:
        clusters[c].append(mat[i])
    except KeyError:
        clusters[c] = [mat[i]]
    i += 1

colours = ['b', 'r', 'g', 'c', 'm', 'y', 'k', 'w']
lines = []
i = 0
for key in clusters.keys():
    i = i % len(colours)
    for j, time_series in enumerate(clusters[key]):
        line = plt.plot(time_series, colours[i])
        if j == 0:
            lines.append(line)
    i += 1
plt.legend(lines, ["Cluster %d" % i for i, k in enumerate(clusters.keys())])

l = len(clusters.values()[0][0])
if l < 5:
    plt.xticks(range(l + 1), range(l + 1))

plt.ylabel("Intensity [a.u.]")
plt.xlabel("Time Points")

plt.savefig(output, format=format)
{'fraction_non_alphanumeric': 0.17450743868114194, 'fraction_numerical': 0.01648572577402493, 'mean_word_length': 3.1885521885521886, 'pattern_counts': {'":': 4, '<': 12, '<?xml version=': 0, '>': 11, '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': '2622491', 'n_tokens_mistral': 986, 'n_tokens_neox': 953, 'n_words': 265}