<commit_before>import matplotlib
# Force matplotlib to not use any Xwindows backend.
matplotlib.use('Agg')

from matplotlib import pyplot as plt
from database import Database
from similarity import Similarity

db = Database()
db.connect()
try:
    fig = plt.figure()
    ax = fig.add_subplot(111)
    similarity = Similarity(db)
    clusterNr = 1
    
    totalAverage = similarity.averageWordImportanceDict(articleId for (articleId,) in db.iterQuery("SELECT id FROM article"))
    #zeroVector = {}
    for (clusterId, centroid) in db.iterQuery("SELECT Id, Centroid FROM cluster"):
        #distances = [similarity.distanceToVector(article, zeroVector) for (article,) in db.iterQuery("SELECT Id FROM article WHERE Cluster=%s", clusterId)]
        #ax.plot([clusterNr]*len(distances), distances, 'o')
        
        similarities = [similarity.similarityToVector(article, totalAverage) for (article,) in db.iterQuery("SELECT Id FROM article WHERE Cluster=%s", clusterId)]
        ax.plot([clusterNr]*len(similarities), similarities, 'o')
        
        #Plot average
        average = similarity.averageWordImportanceDict(articleId for (articleId,) in db.iterQuery("SELECT Id FROM article WHERE Cluster=%s", clusterId))<commit_msg>Fixes for plot<commit_after>import matplotlib
# Force matplotlib to not use any Xwindows backend.
matplotlib.use('Agg')

from matplotlib import pyplot as plt
from database import Database
from similarity import Similarity

db = Database()
db.connect()
try:
    fig = plt.figure()
    ax = fig.add_subplot(111)
    similarity = Similarity(db)
    clusterNr = 1
    
    totalAverage = similarity.averageWordImportanceDict([articleId for (articleId,) in db.iterQuery("SELECT id FROM article")])
    #zeroVector = {}
    for (clusterId, centroid) in db.iterQuery("SELECT Id, Centroid FROM cluster"):
        #distances = [similarity.distanceToVector(article, zeroVector) for (article,) in db.iterQuery("SELECT Id FROM article WHERE Cluster=%s", clusterId)]
        #ax.plot([clusterNr]*len(distances), distances, 'o')
        
        similarities = [similarity.similarityToVector(article, totalAverage) for (article,) in db.iterQuery("SELECT Id FROM article WHERE Cluster=%s", clusterId)]
        ax.plot([clusterNr]*len(similarities), similarities, 'o')
        
        #Plot average
        average = similarity.averageWordImportanceDict(articleId for (articleId,) in db.iterQuery("SELECT Id FROM article WHERE Cluster=%s", clusterId))
{'fraction_non_alphanumeric': 0.10854597002835156, 'fraction_numerical': 0.0032401782098015392, 'mean_word_length': 4.334773218142549, 'pattern_counts': {'":': 0, '<': 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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4205840', 'n_tokens_mistral': 737, 'n_tokens_neox': 694, 'n_words': 205}