Using arbitrary polygons as markers in Makie.jl

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: API Reference AbstractPlotting · Makie.jl could be used to produce an actual plot)

1 Like

You mean something like this :

Legend · Makie.jl (juliaplots.org)

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

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.

Here the marker attribute is listed for available types. Example gallery has some marker examples with symbols, unicode character and an image.

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 , which is the first hit I get after googling “matplotlib available marker types”

if you check the help for scatter, it says that

?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/

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.

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

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

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

2 Likes

@sudete suggests what I’d do! :wink:

2 Likes

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.

1 Like

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

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.

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

Flocking, Bacteria Growth.

For the animations to work we provide the markers to an observable (source), and introduced some helper functions.

1 Like