Makie density2d scatter plot

I tried to reproduce Gadfly’s density2d in Makie as in the example Density2D. Appreciate your help. Thanks.

AOG may have you covered:
http://juliaplots.org/AlgebraOfGraphics.jl/stable/generated/penguins/

1 Like

Or if you want to cook it yourself, you could do something like that:

using GLMakie
using StatsBase

x = randn(2, 1000)
x_hist = fit(Histogram, Tuple(eachrow(x)), nbins=20)

fig = Figure()
ax1 = Axis(fig[1, 1])

scatter!(ax1, x)
contour!(ax1, x_hist)

fig

1 Like

Thanks. The example solution looks good.

I think I prefer the raw solution.

1 Like

Is there a way to smoothen the contour (circle-like) instead of jagged, as in AOG example?

Unfortunately I don’t know.
Maybe if you use different parameters for the histogram creation.

I’m not at my computer, so I can’t show you a proper example. But here I made a density contour in Makie using KernelDensity.jl if you look on their GitHub readme you can see that it’s possible to change the bandwidth for each axis, which should hopefully do what you want.

2 Likes

Thank you. This has exactly meet my expectation.

2 Likes