<jupyter_start><jupyter_text>Inserisci titolo grafico qui<jupyter_code>import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.ticker import StrMethodFormatter
from math import ceil, floor


OUT_FOLDER = 'grafici/DurataAvvistamenti'
FIGURE_SIZE = (20, 8)

%matplotlib inline
DATASET = 'ufos.csv'
data = pd.read_csv(DATASET)
len(data)
bins = [0, 10, 30, 60 * 1, 60 * 2, 60 * 5, 60 * 15, 60*60, 60*60 * 4, 60*60*24, 10000000000]
def find_bin(x):
    for i in range(len(bins[:-1])):
        if bins[i] <= x < bins[i+1]:
            return i
    return len(bins)
counts = data['duration (seconds)'].groupby(find_bin).size()

def between(a, b):
    return len(data[(data['duration (seconds)'] >= a) & (data['duration (seconds)'] < b)])

counts = [between(bins[i], bins[i+1]) for i in range(len(bins[:-1]))]
TITLE = 'Durata degli avvistamenti'
YLABEL = 'Numero di avvistamenti'
XLABEL = "Durata dell'avvistamento"
LABELS = [
    '10 secondi', '30 secondi', '1 minuto', '2 minuti', '5 minuti', 
    '15 minuti', '1 ora', '4 ore', '1 giorno', 'di più'
]
fig, ax = plt.subplots(figsize=FIGURE_SIZE)

bars = ax.bar(range(len(counts)), counts)

ax.set_xticks(range(len(LABELS)))
ax.set_xticklabels(LABELS)
ax.set_title(TITLE)
ax.set_ylabel(YLABEL)
ax.set_xlabel(XLABEL)

for spine in ['left', 'right', 'top', 'bottom']:
    ax.spines[spine].set_visible(False)

# Switch off ticks
ax.tick_params(
    axis="both", 
    which="both", 
    bottom=False, 
    top=False, 
    labelbottom=True, 
    left=False, 
    right=False, 
    labelleft=True, 
)

# Draw vertical axis lines
vals = ax.get_yticks()
for tick in vals:
    ax.axhline(y=tick, linestyle='dashed', alpha=0.4, color='#eeeeee', zorder=1)

plt.savefig(f'{OUT_FOLDER}/BarChart.png')
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16259711431742507, 'fraction_numerical': 0.03662597114317425, 'mean_word_length': 4.599378881987578, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '392529', 'license': 'MIT', 'n_tokens_mistral': 786, 'n_tokens_neox': 722, 'n_words': 167, 'path': 'DurataAvvistamenti.ipynb', 'repo_name': 'mrkct/scivis-progetto', 'size': '1802'}