Commit 484728ec authored by Elias's avatar Elias

Number of words by Bin

parent 0e22dcc6
import csv
from collections import defaultdict
import matplotlib.pyplot as plt
input_file = "res7_Random.csv"
# Dictionnaire pour compter les lignes par Bin
bin_counts = defaultdict(int)
with open(input_file, mode="r", newline="") as f:
reader = csv.reader(f)
next(reader)
for row in reader:
bin_value = int(row[4]) # colonne 'Bin'
bin_counts[bin_value] += 1
# Trier les bins
bins = sorted(bin_counts.keys())
counts = [bin_counts[b] for b in bins]
# Création du bar chart
plt.figure(figsize=(10, 6))
bars = plt.bar([str(b) for b in bins], counts, color='skyblue')
# Ajouter les nombres au-dessus des barres
for bar in bars:
height = bar.get_height()
plt.text(bar.get_x() + bar.get_width()/2, height + 0.5, str(height),
ha='center', va='bottom', fontsize=10)
plt.title("Number of words by Bin")
plt.xlabel("Bin")
plt.ylabel("Number of words")
plt.grid(axis='y', linestyle='--', alpha=0.7)
plt.tight_layout()
plt.show()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment