# Using arbitrary polygons as markers in Makie.jl

**URL:** https://discourse.julialang.org/t/using-arbitrary-polygons-as-markers-in-makie-jl/53690
**Category:** New to Julia
**Tags:** plotting, makie
**Created:** [January 20, 2021, 10:44pm UTC](https://discourse.julialang.org/t/using-arbitrary-polygons-as-markers-in-makie-jl/53690 "2021-01-20T22:44:26Z")
**Posts on this page:** 16
**Page:** 1

<div class="post-metadata">

### Author: ![Datseris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/datseris/32/13406_2.png) [@Datseris](https://discourse.julialang.org/u/Datseris)
#### Post date: [January 20, 2021, 10:44pm UTC](https://discourse.julialang.org/t/using-arbitrary-polygons-as-markers-in-makie-jl/53690/1 "2021-01-20T22:44:26Z")

</div>

Hi,

I know I can make any polygon as a vector of `Point2f0` and plot it with `poly!`. However what I’d like to do is use this polygon as a _marker_ for a scatter plot.

is this possible? how? I couldn’t find something in the docs. (BTW the it would be really helpful if the docs have a plot that shows all available markers, this docstring: [http://makie.juliaplots.org/stable/abstractplotting\_api.html#AbstractPlotting.available\_marker\_symbols-Tuple{}](http://makie.juliaplots.org/stable/abstractplotting_api.html#AbstractPlotting.available_marker_symbols-Tuple%7B%7D) could be used to produce an actual plot)

---

<div class="post-metadata">

### Author: ![lazarusA](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lazarusa/32/6571_2.png) [@lazarusA](https://discourse.julialang.org/u/lazarusA)
#### Post date: [January 21, 2021, 6:09am UTC](https://discourse.julialang.org/t/using-arbitrary-polygons-as-markers-in-makie-jl/53690/2 "2021-01-21T06:09:11Z")

</div>

You mean something like this :

[Legend · Makie.jl (juliaplots.org)](http://makie.juliaplots.org/stable/makielayout/llegend.html#Creating-legend-entries-manually)

There, the last entry is a poly marker [scatter].

---

<div class="post-metadata">

### Author: ![Datseris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/datseris/32/13406_2.png) [@Datseris](https://discourse.julialang.org/u/Datseris)
#### Post date: [January 21, 2021, 9:15am UTC](https://discourse.julialang.org/t/using-arbitrary-polygons-as-markers-in-makie-jl/53690/3 "2021-01-21T09:15:07Z")

</div>

No, that’s not what I’m looking for. This adds a polygon as an entry to a legend. I want to scatter plot markers whose shape is a polygon.

---

<div class="post-metadata">

### Author: ![tomaklutfu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomaklutfu/32/2411_2.png) [@tomaklutfu](https://discourse.julialang.org/u/tomaklutfu)
#### Post date: [January 21, 2021, 9:52am UTC](https://discourse.julialang.org/t/using-arbitrary-polygons-as-markers-in-makie-jl/53690/4 "2021-01-21T09:52:43Z")

</div>

Here the [`marker`](http://makie.juliaplots.org/stable/generated/plot-attributes.html#List-of-attributes) attribute is listed for available types. [Example gallery](http://juliaplots.org/MakieReferenceImages/gallery/index.html) has some `marker` examples with [symbols](http://juliaplots.org/MakieReferenceImages/gallery//available_markers/index.html), [unicode character](http://juliaplots.org/MakieReferenceImages/gallery//pulsing_marker/index.html) and [an image](http://juliaplots.org/MakieReferenceImages/gallery//image_scatter/index.html).

---

<div class="post-metadata">

### Author: ![Datseris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/datseris/32/13406_2.png) [@Datseris](https://discourse.julialang.org/u/Datseris)
#### Post date: [January 21, 2021, 10:00am UTC](https://discourse.julialang.org/t/using-arbitrary-polygons-as-markers-in-makie-jl/53690/5 "2021-01-21T10:00:18Z")

</div>

The plots you cite are outdated w.r.t. current Makie so I’m not sure how trustworthy they are. They are also not what I am expecting. I am expecting something like this: [matplotlib.markers — Matplotlib 3.3.3 documentation](https://matplotlib.org/3.3.3/api/markers_api.html) , which is the first hit I get after googling “matplotlib available marker types”

---

<div class="post-metadata">

### Author: ![lazarusA](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lazarusa/32/6571_2.png) [@lazarusA](https://discourse.julialang.org/u/lazarusA)
#### Post date: [January 21, 2021, 10:09am UTC](https://discourse.julialang.org/t/using-arbitrary-polygons-as-markers-in-makie-jl/53690/6 "2021-01-21T10:09:45Z")

</div>

if you check the help for scatter, it says that

```julia
?marker
.
marker HyperSphere{2,T} where T
.
.

```

which suggest one should define custom markers as in here [including polygons]  
[https://juliageometry.github.io/GeometryBasics.jl/stable/](https://juliageometry.github.io/GeometryBasics.jl/stable/)

I did try some, but unfortunately none of them worked. No errors, but not points [markers] were plotted. Probably someone else, that knows better the internals could help here.

---

<div class="post-metadata">

### Author: ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)
#### Post date: [January 21, 2021, 11:31am UTC](https://discourse.julialang.org/t/using-arbitrary-polygons-as-markers-in-makie-jl/53690/7 "2021-01-21T11:31:49Z")

</div>

It looks like `marker` doesn’t accept a `Polygon`, but it works if you make a `Mesh` from it:

```julia
p = Polygon([Point2f0(0), Point2f0(1), Point2f0(1,0)]);
meshscatter(rand(Point2f0, 10), marker=GeometryBasics.mesh(p), color=:red)

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/c/e/ce0e13b6ffd0b28aa0a8292bcfd40ac584ac157b.png)

Looks like shading is on by default even for 2D plots, so you might want to add `shading=false`.

---

<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: [January 21, 2021, 4:59pm UTC](https://discourse.julialang.org/t/using-arbitrary-polygons-as-markers-in-makie-jl/53690/8 "2021-01-21T16:59:31Z")

</div>

@sijo suggests what I’d do! 😉

---

<div class="post-metadata">

### Author: ![Datseris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/datseris/32/13406_2.png) [@Datseris](https://discourse.julialang.org/u/Datseris)
#### Post date: [January 21, 2021, 5:03pm UTC](https://discourse.julialang.org/t/using-arbitrary-polygons-as-markers-in-makie-jl/53690/9 "2021-01-21T17:03:42Z")

</div>

I’m making a plotting framework for Agents.jl where users can plot their agents as scatter markers. It is convenient for us to do everything with `scatter` and forward splatted keywords to scatter.

Doesn’t it make more sense if `scatter` could accept a `Polygon` directly as a marker, instead of me writing an `if` clause? It might be that more people in the future will want to scatter plot something with arbitrary polygons.

---

<div class="post-metadata">

### Author: ![lazarusA](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lazarusa/32/6571_2.png) [@lazarusA](https://discourse.julialang.org/u/lazarusA)
#### Post date: [March 2, 2021, 8:33pm UTC](https://discourse.julialang.org/t/using-arbitrary-polygons-as-markers-in-makie-jl/53690/10 "2021-03-02T20:33:21Z")

</div>

Hello,  
I believe this question was answer in Slack [black hole], could you please share the solution here.

---

<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: [March 2, 2021, 8:41pm UTC](https://discourse.julialang.org/t/using-arbitrary-polygons-as-markers-in-makie-jl/53690/11 "2021-03-02T20:41:54Z")

</div>

I think we settled on doing `poly(vector_of_polygons)`. The only thing is that it’s currently buggy to add vertices to these polygons interactively. But in the use case that we talked about, only the rotation and size was changed.

---

<div class="post-metadata">

### Author: ![Libbum](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/libbum/32/3935_2.png) [@Libbum](https://discourse.julialang.org/u/Libbum)
#### Post date: [March 2, 2021, 8:56pm UTC](https://discourse.julialang.org/t/using-arbitrary-polygons-as-markers-in-makie-jl/53690/12 "2021-03-02T20:56:23Z")

</div>

`poly` was indeed the solution. Here are a few examples using it:

[Flocking](https://juliadynamics.github.io/Agents.jl/stable/examples/flock/), [Bacteria Growth](https://juliadynamics.github.io/Agents.jl/stable/examples/growing_bacteria/).

For the animations to work we provide the markers to an observable ([source](https://github.com/JuliaDynamics/InteractiveDynamics.jl/blob/b4db4c3a27afd7b910ba7ab075a749e797ed3dea/src/agents/stepping.jl#L49-L55)), and introduced [some helper functions](https://github.com/JuliaDynamics/InteractiveDynamics.jl/blob/02f540be4d657ef8cb19a1a3a19eba9ab496631e/src/utils.jl#L112-L136).

---

<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 29, 2021, 8:31am UTC](https://discourse.julialang.org/t/using-arbitrary-polygons-as-markers-in-makie-jl/53690/13 "2021-09-29T08:31:33Z")

</div>

> [@sijo](#):
>
> ```julia-auto
> p = Polygon([Point2f0(0), Point2f0(1), Point2f0(1,0)]);
> meshscatter(rand(Point2f0, 10), marker=GeometryBasics.mesh(p), color=:red)
> 
> ```

This solution works nicely, but as with the `poly` solution, I’m wondering if there’s a way to change the space-units from data to pixel. When you zoom in on a regular scatter-marker the size of the marker doesn’t change, which is great. I would have liked to be able to create a custom marker (from a polygon) that behaves similarly.

## For more context

I’m trying to create and use a new rotated drop-shaped marker, which works really well following the docs [https://makie.juliaplots.org/stable/documentation/recipes/index.html#multiple\_argument\_conversion\_with\_convert\_arguments:](https://makie.juliaplots.org/stable/documentation/recipes/index.html#multiple_argument_conversion_with_convert_arguments:)

```julia-auto
using CoordinateTransformations, Rotations

struct DirectedDrop{T<:AbstractVector}
  c::T
  θ::Float64
end

function Makie.convert_arguments(::PointBased, x::DirectedDrop)
  f = Translation(x.c) ∘ LinearMap(Angle2d(x.θ))
  n = 64
  ([f(Point2f(cos(t), sin(t)*sin(t/2)^2)) for t in range(0, 2π, n + 1)[1:end-1]], )
end

c = Point2f(2,3)
dd = Node(DirectedDrop(c, 0.0))
poly(dd, axis = (aspect = DataAspect(), ))

```

 ![a](https://global.discourse-cdn.com/julialang/original/3X/7/2/72d13997fb10c02b00c97d1c3a3cbbfdf984fd40.png)

My question is, what is the best way to plug in the whole interplay between `MarkerSpace` versus `DataSpace`? And as a side-question, in the decomposition of my `DirectedDrop`, what is the correct way to specify the number of vertices I use to create the drop (right now, I just have it hard-coded to 64)?

---

<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 29, 2021, 9:03am UTC](https://discourse.julialang.org/t/using-arbitrary-polygons-as-markers-in-makie-jl/53690/14 "2021-09-29T09:03:07Z")

</div>

Actually, there’s a much simpler solution to this. I could use a unicode droplet character and then simply:

```julia
n = 10
scatter(rand(Point2f0, n), marker='↓', rotation = 2π*rand(n))

```

where the ↓ would be replaced by say something like 🌢. But currently I couldn’t find any droplet charachters that rendered correctly on my figure (I’m just getting the empty rectangle symbol).

---

<div class="post-metadata">

### Author: ![aachener](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aachener/32/18112_2.png) [@aachener](https://discourse.julialang.org/u/aachener)
#### Post date: [December 30, 2021, 8:14am UTC](https://discourse.julialang.org/t/using-arbitrary-polygons-as-markers-in-makie-jl/53690/15 "2021-12-30T08:14:05Z")

</div>

maybe this will help you if you look into the markershape attribute in the table.

[Series Attributes · Plots (juliaplots.org)](http://docs.juliaplots.org/latest/generated/attributes_series/)

---

<div class="post-metadata">

### Author: ![Datseris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/datseris/32/13406_2.png) [@Datseris](https://discourse.julialang.org/u/Datseris)
#### Post date: [December 31, 2021, 2:50pm UTC](https://discourse.julialang.org/t/using-arbitrary-polygons-as-markers-in-makie-jl/53690/16 "2021-12-31T14:50:34Z")

</div>

Your reply isn’t even about Makie.jl though…
