Published
Edited
Apr 26, 2022
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
kde = require('fast-kde')
Insert cell
selected_dataset = traffic_2021_by_weather[0]
Insert cell
locations = selected_dataset[1].map(d=>d.location)
Insert cell
lat_ext = d3.extent(locations.map(d=>d[0]))
Insert cell
lon_ext = d3.extent(locations.map(d=>d[1]))
Insert cell
values2d = [
[2.1, 2],
[2.9, 3],
[3.1, 4],
[5.7, 5],
[6.6, 6],
[8.5, 7]
];
Insert cell
density2d = kde.density2d(locations, { bandwidth: 1, extent: [[-88, -86], [34, 37.5]], bins : [600, 600] })
Insert cell
viewof bw2d = Inputs.range([0.1, 3], {step: 0.01, value: 1, label: 'Bandwidth'})
Insert cell
Insert cell
Insert cell
density2d.bandwidth(bw2d).heatmap({ color: d3.interpolateBlues }) // returns an HTML canvas
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
traffic_data_weather = FileAttachment("Processed_Traffic_Accidents-1.json").json()
Insert cell
traffic_2021_by_weather = d3.groups(traffic_2021, d=>d.weather_description).slice(0, 4
).sort((a, b) => d3.descending(a[1].length, b[1].length))
Insert cell
sorted_traffic_year = traffic_data_weather.slice().sort((a, b) => d3.descending(a.year, b.year))
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more