-
Notifications
You must be signed in to change notification settings - Fork 2k
Description
I'm running into a situation where it would be nice to be able to set or override the zorder for different groups within a scatterplot, and it doesn't seem like there's an obvious way to do this (short of overlaying multiple scatterplots by hand and then adjusting all the elements after).
For example, I have a scatterplot with three distinct groups (call them A, B, and C), which I'm currently mapping to hue. It so happens that groups B and C are tightly clustered, while group A is both larger and more dispersed. As a result, the A group tends to visually crowd out the B and C groups. I can fudge this with transparency, but it's not a terribly satisfying solution.
If it was possible to set the zorder for each group, it would be easy to have the B and C groups draw above the A group and prevent crowding without relying on transparency. I tried to do this in a postprocessing step, but it appears that all scatterplot points are put into one collection object, so there's no direct way to update the zorder by group.
For right now, I can hack around this by sorting the dataframe prior to calling scatterplot()
to produce my preferred draw order. I don't think this is guaranteed behavior though, so it doesn't strike me as a stable or recommended approach.
I expect that exposing zorder here might entail quite a bit of complexity under the hood - it seems like matplotlib pathcollections only allow zorder at the collection level, not individual elements. That probably means that the collection would need to be broken into multiple collections, and if zorder is mapped to a field with high cardinality (or continuous values) that could get unwieldy.
Still, it seems like it could be useful to provide some way to influence the draw order, so I figured I'd raise the issue here.