Code
import pandas as pd
import numpy as np
import altair as alt
"vegafusion") # for altair to work with large datasets alt.data_transformers.enable(
DataTransformerRegistry.enable('vegafusion')
import pandas as pd
import numpy as np
import altair as alt
"vegafusion") # for altair to work with large datasets alt.data_transformers.enable(
DataTransformerRegistry.enable('vegafusion')
= pd.read_csv('Histogram.csv') overall_time_data
# Title Function for plots
def chart_title_func(title, subtitle = False):
if subtitle == False:
return alt.Title(title, font = 'Century',
= 18,
fontSize = 'top',
orient = 20)
offset else:
return alt.Title(title, font = 'Century',
= 18,
fontSize = 'top',
orient = 20,
offset = subtitle) subtitle
= alt.Scale(
color_scale type='linear',
='redyellowgreen',
scheme=0,
domainMid= True
reverse
)
= f"Arrest by hours"
hist_title
= alt.Chart(overall_time_data, title = chart_title_func(hist_title, [f"This Histogram of All time data from January, 2010 to September, 2023."]))\
hist \
.mark_bar()
.encode("time_arr:Q", bin=alt.Bin(maxbins=30), axis=alt.Axis(labelAngle=-45), title = 'Time'),
alt.X('count()', title = 'Arrest Count'),
alt.Y(=["count()"],
tooltip= alt.Color('count():N', scale=color_scale)
color
).properties(=900,
width=250
height
)
hist