Napari custom point marker

Hi @sofroniewn et al.,

Asking here because it might be useful for others.

Is there an obvious/easier way to use a custom marker for a points layer? Specifically I would like to do something like:

  • Point type A is color A
  • Point type B is color B
  • A point which is both type A and B is half and half colors A & B

Is there a way to do something like this with a points layer? Or would it be a case of superimposing custom images over the top?


Hi @adamltyson

Yes! I think we should be able to do that with a points layer. You can see in this add_points_with_properties example how we can color the points with a custom property. Does this look like what you want?

Maybe @kevinyamauchi can add more detail too!

Thanks @sofroniewn,

It’s not quite what I need, I need a more custom point marker for N classes of points. If for example I have three properties that points can have (A, B, C), represented by three colors (red, green, blue) and I have points that can have any combination of these points, then I need something like:

  • Point 1 has property A, and so is red
  • Point 2 has property B, so is green
  • Point 3 has properties A & B and so is half red and half green (ideally two hemispheres)
  • Point 4 has properties A, B & C, and so is 1/3 red, 1/3 green, 1/3 blue (think pie chart)

Does this make sense?

It’s probably not a very common request, so I’m wondering if the best way is for me to create some custom SVGs, and just overlay them myself.

Ah ok - I got it!! Funnily I got the exact same request from my dad (also a neuroscientist that does cellular imaging) so its certainly not a one off!! (His properties were binarized expression of marker genes).

He also wanted a nice way in the GUI to adjust which properties each cell had and didn’t have.

If you could live with blended colors i.e. half red/ half green gets colored brown or whatever color that is, then I think we could get there fairly quickly using the properties attribute. Clearly that’s not sufficient for visualization, but I just want to make sure from a data standpoint we can do that at least.

As to pie chart like markers, it could be done, but we’d need to drop down the to vispy shader layer to make some changes. Probably the biggest question is what the color setting API should look like, as now we can’t just have a list of N coordinates and a list of N colors, we need a list of N lists of colors …

Curious what @kevinyamauchi thinks of this now

Maybe it isn’t so niche, I’ve realised we actually have >2 independent use cases for this, but (to me) it seems difficult for napari to handle this gracefully.

I thought I could do this with blended colors (or combinations of face/edge colors) by having 2^n - 1 properties rather than N. That works well for my initial use case (N=3), but not so much for the other case (N=7-9).

I figure it would be easy enough to generate 2^n -1 “pie chart” svg or similar for n points (within reason), if I were to try this, how easy is it to add these in vispy?

As a much faster and easier workaround, I might suggest adding 7-9 jittered points layers so that points are not quite on top of each other, but not jittered enough that objects fuse. Do you have the resolution for this in the imaging channel, @adamltyson?

Thanks @jni. I’m not sure this will work though, the points are very close (likely overlapping), and if I understand your suggestion properly, I think that a point with properties A+B will just look like an A and a B point right next to each other.

Yeah, that’s what I was getting at with resolution. Essentially offset points into a circle around the actual point. But if they are too close together that won’t do!

Hey @adamltyson! Thank you for this post. I think it is a really interesting use case. I definitely need to think more about this, but a few thoughts.

I agree the dithered points is not ideal. However, I am curious if you did something like make all dithered points corresponding to a single point have the same face color and then encode the properties via edge color (or vice versa). That way, one knows that the dithered points are multiple annotations of the same point as opposed to multiple points. Again, not ideal, but may be sufficient for some cases.

We can consider contributing new marker types back to vispy (I believe they are defined here). As of now, all points within a single MarkersVisual (the visual type we use to display points) must have the same symbol. Thus, if we wanted to have multiple point symbol types per visual, I think we would have to either add that functionality in or do something like a compound visual of multiple markers visuals (i.e., one per point symbol). I am not sure how much work this would be to change this, but it definitely seems useful. I can look more into this.

Also, I think this could be related to this issue discussing being able to rending single molecule localziation data (e.g., give each point a symbol that corresponds to the point spread function). In that issue, Loic links to this example of rendering many different point types with vispy.

Thanks @kevinyamauchi.

However, I am curious if you did something like make all dithered points corresponding to a single point have the same face color and then encode the properties via edge color (or vice versa).

I didn’t consider that, it’s a great idea, but annoyingly still doesn’t work for my immediate use case. I have an 8mm x 1.1mm image, with points separated by as little as 50um, so each one needs to be as large as possible, and the color coding totally non-ambiguous.

For now, I’ll see if I can mock something up just by overlaying image layers, but it would be cool to see how the points layer can be extended to deal with more complex point properties.

Just in case I didn’t explain it properly, this is the sort of figure I was after (I just generated it by overlaying image layers). Showing cells with various properties, overlaid on an atlas.

1 Like

I’m not sure if it’s possible to have semi-transparent points displayed, but that might be better than jittered points layers if it’s possible to do

One more thought might be concentric rings - I know it’s not ideal, but we could do that right away as we have a ring shape for points