# Makie density2d scatter plot

**URL:** https://discourse.julialang.org/t/makie-density2d-scatter-plot/65869
**Category:** Tooling
**Tags:** plotting, makie
**Created:** [August 5, 2021, 9:27am UTC](https://discourse.julialang.org/t/makie-density2d-scatter-plot/65869 "2021-08-05T09:27:30Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![Humphrey\_Lee](https://avatars.discourse-cdn.com/v4/letter/h/a88e4f/32.png) [@Humphrey\_Lee](https://discourse.julialang.org/u/Humphrey_Lee)
#### Post date: [August 5, 2021, 9:27am UTC](https://discourse.julialang.org/t/makie-density2d-scatter-plot/65869/1 "2021-08-05T09:27:30Z")

</div>

I tried to reproduce Gadfly’s density2d in Makie as in the example [Density2D](http://gadflyjl.org/stable/gallery/geometries/#%5BGeom.density2d%5D(@ref)). Appreciate your help. Thanks.

---

<div class="post-metadata">

### Author: ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)
#### Post date: [August 5, 2021, 9:40am UTC](https://discourse.julialang.org/t/makie-density2d-scatter-plot/65869/2 "2021-08-05T09:40:30Z")

</div>

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

---

<div class="post-metadata">

### Author: ![fedario](https://avatars.discourse-cdn.com/v4/letter/f/f14d63/32.png) [@fedario](https://discourse.julialang.org/u/fedario)
#### Post date: [August 5, 2021, 9:49am UTC](https://discourse.julialang.org/t/makie-density2d-scatter-plot/65869/3 "2021-08-05T09:49:34Z")

</div>

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

```plaintext
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

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/a/0/a00ff5f21c8f6349ce4f94ba06553eaf8560b2fc.png)

---

<div class="post-metadata">

### Author: ![Humphrey\_Lee](https://avatars.discourse-cdn.com/v4/letter/h/a88e4f/32.png) [@Humphrey\_Lee](https://discourse.julialang.org/u/Humphrey_Lee)
#### Post date: [August 5, 2021, 10:45am UTC](https://discourse.julialang.org/t/makie-density2d-scatter-plot/65869/4 "2021-08-05T10:45:00Z")

</div>

Thanks. The example solution looks good.

---

<div class="post-metadata">

### Author: ![Humphrey\_Lee](https://avatars.discourse-cdn.com/v4/letter/h/a88e4f/32.png) [@Humphrey\_Lee](https://discourse.julialang.org/u/Humphrey_Lee)
#### Post date: [August 5, 2021, 10:56am UTC](https://discourse.julialang.org/t/makie-density2d-scatter-plot/65869/5 "2021-08-05T10:56:01Z")

</div>

I think I prefer the raw solution.

---

<div class="post-metadata">

### Author: ![Humphrey\_Lee](https://avatars.discourse-cdn.com/v4/letter/h/a88e4f/32.png) [@Humphrey\_Lee](https://discourse.julialang.org/u/Humphrey_Lee)
#### Post date: [August 5, 2021, 11:52am UTC](https://discourse.julialang.org/t/makie-density2d-scatter-plot/65869/6 "2021-08-05T11:52:08Z")

</div>

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

---

<div class="post-metadata">

### Author: ![fedario](https://avatars.discourse-cdn.com/v4/letter/f/f14d63/32.png) [@fedario](https://discourse.julialang.org/u/fedario)
#### Post date: [August 7, 2021, 10:17am UTC](https://discourse.julialang.org/t/makie-density2d-scatter-plot/65869/7 "2021-08-07T10:17:47Z")

</div>

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

---

<div class="post-metadata">

### Author: ![EvoArt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/evoart/32/25357_2.png) [@EvoArt](https://discourse.julialang.org/u/EvoArt)
#### Post date: [August 7, 2021, 8:13pm UTC](https://discourse.julialang.org/t/makie-density2d-scatter-plot/65869/8 "2021-08-07T20:13:10Z")

</div>

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.

 ![Screenshot_2021-08-07-21-02-51-319_com.miui.gallery](https://global.discourse-cdn.com/julialang/original/3X/a/7/a79d8c5ea5f311ef1f6c0a761525b9ea26ae4eae.jpeg)

---

<div class="post-metadata">

### Author: ![Humphrey\_Lee](https://avatars.discourse-cdn.com/v4/letter/h/a88e4f/32.png) [@Humphrey\_Lee](https://discourse.julialang.org/u/Humphrey_Lee)
#### Post date: [August 8, 2021, 5:39am UTC](https://discourse.julialang.org/t/makie-density2d-scatter-plot/65869/9 "2021-08-08T05:39:36Z")

</div>

Thank you. This has exactly meet my expectation.

---

<div class="post-metadata">

### Author: ![e3c6](https://avatars.discourse-cdn.com/v4/letter/e/e79b87/32.png) [@e3c6](https://discourse.julialang.org/u/e3c6)
#### Post date: [March 2, 2025, 4:31pm UTC](https://discourse.julialang.org/t/makie-density2d-scatter-plot/65869/10 "2025-03-02T16:31:06Z")

</div>

> [@sdanisch](#):
>
> AOG may have you covered:  
> [http://juliaplots.org/AlgebraOfGraphics.jl/stable/generated/penguins/](http://juliaplots.org/AlgebraOfGraphics.jl/stable/generated/penguins/)

This link is broken. Is there an updated link?

---

<div class="post-metadata">

### Author: ![asinghvi17](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/asinghvi17/32/8272_2.png) [@asinghvi17](https://discourse.julialang.org/u/asinghvi17)
#### Post date: [March 4, 2025, 8:08pm UTC](https://discourse.julialang.org/t/makie-density2d-scatter-plot/65869/11 "2025-03-04T20:08:03Z")

</div>

> **[Getting started 🐧 | AlgebraOfGraphics](https://aog.makie.org/v0.9.3/tutorials/getting-started#:~:text=The%20data%20and%20the%20linear%20fit%20can%20also%20be%20added%20back%20to%20the%20plot%3A)**
>
> Documentation for AlgebraOfGraphics.jl
