Fayetteville Arrests Histogram

1 Imports

Code
import pandas as pd

import numpy as np

import altair as alt
alt.data_transformers.enable("vegafusion") # for altair to work with large datasets
DataTransformerRegistry.enable('vegafusion')

2 Reading Data

Code
overall_time_data = pd.read_csv('Histogram.csv')

3 Histogram of Arrest Time

Code
# Title Function for plots

def chart_title_func(title, subtitle = False):
    if subtitle == False:
        return alt.Title(title, font = 'Century', 
                         fontSize = 18, 
                         orient = 'top', 
                         offset = 20)
    else:
        return alt.Title(title, font = 'Century', 
                         fontSize = 18, 
                         orient = 'top', 
                         offset = 20, 
                         subtitle = subtitle)
Code
color_scale = alt.Scale(
    type='linear',
    scheme='redyellowgreen',
    domainMid=0,
    reverse = True
)

hist_title = f"Arrest by hours"

hist = alt.Chart(overall_time_data, title = chart_title_func(hist_title, [f"This Histogram of All time data from January, 2010 to September, 2023."]))\
    .mark_bar()\
    .encode(
        alt.X("time_arr:Q", bin=alt.Bin(maxbins=30), axis=alt.Axis(labelAngle=-45), title = 'Time'),
        alt.Y('count()', title = 'Arrest Count'),
        tooltip=["count()"],
        color = alt.Color('count():N', scale=color_scale)
    ).properties(
        width=900,
        height=250
    )


hist
Figure 1: Histogram for Arrest By hours in Faytteville