NBA shot chart

Author

math4mad

Code
using Images
import CairoMakie:Axis
include("utils.jl")
[ Info: loading success
Code
img = load("./imgs/halfcourt.png")
xs = range(-250.0, 250.0, length=size(img,1))
ys = range(-50.0,420.0, length=size(img,2))
-50.0:0.37630104083266613:420.0
Code
df=@pipe CSV.File("./data/nba_shot.csv")|>DataFrame|>dropmissing|>Float64.(_)
df.shot=coerce(df.shot, Multiclass)
first(df,10)
10×3 DataFrame
Row x y shot
Float64 Float64 Cat…
1 95.0 242.0 1.0
2 129.0 43.0 0.0
3 20.0 10.0 0.0
4 -127.0 239.0 0.0
5 -13.0 14.0 1.0
6 30.0 252.0 1.0
7 168.0 208.0 0.0
8 130.0 17.0 1.0
9 9.0 21.0 0.0
10 -2.0 264.0 0.0
Code
using GLMakie
fig=Figure()
ax=Axis(fig[1,1])
GLMakie.image!(ax,rotl90(img))


plt = AlgebraOfGraphics.data(df) * mapping(:x, :y,color=:shot)
draw!(fig[1,1],plt * visual(Scatter))
fig

Code
set_aog_theme!()

axis = (width = 150, height = 150)
shot_frequency = AlgebraOfGraphics.data(df) * frequency() * mapping(:shot)
draw(shot_frequency; axis)

Code
let 
  axis = (type = Axis3, width =600, height = 600)
   layer = AlgebraOfGraphics.density() * visual(Wireframe, linewidth=0.05)
   plt = AlgebraOfGraphics.data(df)* layer* mapping(:x,:y) 
   draw(plt; axis)
    
end