# Use 2d marker in Makie \`meshscatter\`

**URL:** <https://discourse.julialang.org/t/use-2d-marker-in-makie-meshscatter/103978>\
**Category:** Performance\
**Tags:** question, plotting, makie\
**Created:** [September 18, 2023, 11:43am UTC](https://discourse.julialang.org/t/use-2d-marker-in-makie-meshscatter/103978 "2023-09-18T11:43:46Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![BambOoxX](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bambooxx/32/22179_2.png) [@BambOoxX](https://discourse.julialang.org/u/BambOoxX)\
**Post date:** [September 18, 2023, 11:43am UTC](https://discourse.julialang.org/t/use-2d-marker-in-makie-meshscatter/103978/1 "2023-09-18T11:43:46Z")

</div>

Hello !

I’m trying to display a large set of 3D points (about 80k) with GLMakie. Initially, I used `meshscatter`, unfortunately my PC doesn’t have a discrete GPU so I’m trying to reduce the stress on the iGPU by using `scatter`. The good thing is that this works well, but in a sense couldn’t I just use a `meshscatter` with `marker=:circle` ?

My experience says that this doesn’t work. I tried with the solution discussed in [Using arbitrary polygons as markers in Makie.jl - #13 by yakir12](https://discourse.julialang.org/t/using-arbitrary-polygons-as-markers-in-makie-jl/53690/13), but this doesn’t handle the plotting of 2D objects in a 3D space.

Any ideas on how to proceed ?

---

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [September 18, 2023, 11:50am UTC](https://discourse.julialang.org/t/use-2d-marker-in-makie-meshscatter/103978/2 "2023-09-18T11:50:42Z")

</div>

Could you post a simple MWE to illustrate what exactly doesn’t work?

---

<div class="post-metadata">

**Author:** ![BambOoxX](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bambooxx/32/22179_2.png) [@BambOoxX](https://discourse.julialang.org/u/BambOoxX)\
**Post date:** [September 18, 2023, 11:55am UTC](https://discourse.julialang.org/t/use-2d-marker-in-makie-meshscatter/103978/3 "2023-09-18T11:55:38Z")

</div>

So for instance you can do

```julia
using GeometryBasics, GLMakie
points = rand(Point3f,1000)

# Does work
scatter(points)
# Does not work
meshscatter(points,marker=:circle)

```

To make it as simple as possible, how can I reproduce the `scatter` output with `meshscatter`.

I tried adding a polygon as a marker like in the linked post above with e.g.

```julia
p = Polygon([Point3f0(0), Point3f0(1,0,0), Point3f0(0,1,0)]);
meshscatter(points,marker=p)

```

but that fails with

> ERROR: MethodError: no method matching earcut\_triangulate(::Vector{Vector{Point{3, Float32}}})

---

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [September 18, 2023, 12:01pm UTC](https://discourse.julialang.org/t/use-2d-marker-in-makie-meshscatter/103978/4 "2023-09-18T12:01:42Z")

</div>

In `meshscatter`’s help it says:

```julia
 • marker::Union{Symbol, GeometryBasics.GeometryPrimitive, GeometryBasics.Mesh} sets the scattered mesh.

```

so I tried:

```julia
meshscatter(points, marker=Sphere(Point3f(0,0,0), 0.2))

```

which results in:

 ![mwe](https://global.discourse-cdn.com/julialang/original/3X/3/1/316bfdd10d5c1758b5a2bb43bbb79359b1738752.png)

---

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [September 18, 2023, 12:07pm UTC](https://discourse.julialang.org/t/use-2d-marker-in-makie-meshscatter/103978/5 "2023-09-18T12:07:55Z")

</div>

Apparently, the default marker is a sphere, so you only need to specify the marker size to change it:

```julia
meshscatter(points, markersize=0.02)

```

---

<div class="post-metadata">

**Author:** ![BambOoxX](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bambooxx/32/22179_2.png) [@BambOoxX](https://discourse.julialang.org/u/BambOoxX)\
**Post date:** [September 18, 2023, 12:14pm UTC](https://discourse.julialang.org/t/use-2d-marker-in-makie-meshscatter/103978/6 "2023-09-18T12:14:30Z")

</div>

Yes, I know this is the default, but in that regard `scatter` and `meshscatter` behave differently. While `meshscatter` plots a sphere, `scatter` plots a circle. I just want to know how to make `meshscatter` plot a circle as well.

---

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [September 18, 2023, 12:20pm UTC](https://discourse.julialang.org/t/use-2d-marker-in-makie-meshscatter/103978/7 "2023-09-18T12:20:20Z")

</div>

I understand. But in the same way you can’t plot a sphere into a 2D axes, you can’t plot a 2D marker (a circle) into a 3D axis.

What exactly do you want it to look like…?

---

<div class="post-metadata">

**Author:** ![BambOoxX](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bambooxx/32/22179_2.png) [@BambOoxX](https://discourse.julialang.org/u/BambOoxX)\
**Post date:** [September 18, 2023, 12:27pm UTC](https://discourse.julialang.org/t/use-2d-marker-in-makie-meshscatter/103978/8 "2023-09-18T12:27:59Z")

</div>

Well if so, how do you explain how `scatter` plots a circle then, even in 3D ?

---

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [September 18, 2023, 12:35pm UTC](https://discourse.julialang.org/t/use-2d-marker-in-makie-meshscatter/103978/9 "2023-09-18T12:35:04Z")

</div>

Not the best answer I got, but: I think it doesn’t? If you rotate the plot around the marker is still round, like a sphere would behave.

---

<div class="post-metadata">

**Author:** ![BambOoxX](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bambooxx/32/22179_2.png) [@BambOoxX](https://discourse.julialang.org/u/BambOoxX)\
**Post date:** [September 18, 2023, 12:38pm UTC](https://discourse.julialang.org/t/use-2d-marker-in-makie-meshscatter/103978/10 "2023-09-18T12:38:37Z")

</div>

Frankly, I would normally agree with you, but the `marker` field of a `scatter` plot remains by default a `:circle`, even in 3D axes like a `LScene`. Also, if you plot around 100k points, at least it’s roughly the threshold I have on my gear, `scatter` is definitely much faster than `meshscatter` so I do not think the objects are the same behind the curtains.

---

<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:** [September 18, 2023, 12:51pm UTC](https://discourse.julialang.org/t/use-2d-marker-in-makie-meshscatter/103978/11 "2023-09-18T12:51:37Z")

</div>

> [@BambOoxX](#):
>
> Initially, I used `meshscatter`, unfortunately my PC doesn’t have a discrete GPU so I’m trying to reduce the stress on the iGPU by using `scatter`. The good thing is that this works well, but in a sense couldn’t I just use a `meshscatter` with `marker=:circle` ?

Why do you want to use meshscatter with marker circle and not scatter? That’s the main question here, which I can’t see an answer for in the thread.  
scatter is exactly faster, because it only draws 2d shapes, which is much easier then drawing 3D meshes, which is the only difference between meshscatter + scatter.  
The only other difference is, that markerspace for meshscatter is always :data… I suppose then, that you want `scatter(points; markerspace=:data)`?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [September 18, 2023, 12:57pm UTC](https://discourse.julialang.org/t/use-2d-marker-in-makie-meshscatter/103978/12 "2023-09-18T12:57:51Z")

</div>

You can also try `scatter(..., marker = Circle)` which I think still uses a different algorithm on the gpu that might be faster than `:circle`

---

<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:** [September 18, 2023, 1:05pm UTC](https://discourse.julialang.org/t/use-2d-marker-in-makie-meshscatter/103978/13 "2023-09-18T13:05:00Z")

</div>

Btw, the fastest is `scatter(...; marker=PixelMarker)`, but that only draws pixel like rects…

---

<div class="post-metadata">

**Author:** ![BambOoxX](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bambooxx/32/22179_2.png) [@BambOoxX](https://discourse.julialang.org/u/BambOoxX)\
**Post date:** [September 18, 2023, 1:39pm UTC](https://discourse.julialang.org/t/use-2d-marker-in-makie-meshscatter/103978/14 "2023-09-18T13:39:50Z")

</div>

The thing is I do like the `meshscatter` result very much in general, and I have made recipes based on that. The only problem is performance on large datasets. So either I need to modify my recipes to call `scatter` or `meshscatter` based on some heuristic on the size of the data, or if it is possible, find a way to make `scatter` look like `meshscatter`, or the other way around.

---

<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:** [September 18, 2023, 1:51pm UTC](https://discourse.julialang.org/t/use-2d-marker-in-makie-meshscatter/103978/15 "2023-09-18T13:51:53Z")

</div>

Well, they’re different functions because they do something different - hence the performance difference… So you cant make them look alike!  
Whats the look you’re aiming for anyways?

---

<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:** [September 18, 2023, 1:54pm UTC](https://discourse.julialang.org/t/use-2d-marker-in-makie-meshscatter/103978/16 "2023-09-18T13:54:39Z")

</div>

To speed up meshscatter, you can try to use a marker with less triangles though.  
Try `marker=Rect` and see if that brings you to the desired framerate

---

<div class="post-metadata">

**Author:** ![BambOoxX](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bambooxx/32/22179_2.png) [@BambOoxX](https://discourse.julialang.org/u/BambOoxX)\
**Post date:** [September 18, 2023, 1:59pm UTC](https://discourse.julialang.org/t/use-2d-marker-in-makie-meshscatter/103978/17 "2023-09-18T13:59:22Z")

</div>

I tried with other markers in `meshscatter`, but it did not feel much smoother in terms of framerate. I guess I’ll just implement the heuristic and switch to `scatter` for large datasets.
