-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Controlling zorder per group in scatterplot #3830
Comments
|
Exactly - but this is the part that makes me a little uncomfortable, as I believe this is undocumented behavior and may be subject to change. (I could imagine this getting very weird in some settings, eg dask dataframes, but I'm sure that's out of scope to consider anyway. 😁) In general, it seems like the index order of records within a dataframe usually doesn't matter for how the resulting figure appears, though obviously it has to in some situations. I'm totally fine with closing this out as "won't implement", but a couple of thoughts come to mind if it could be potentially in scope at some point:
|
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.
The text was updated successfully, but these errors were encountered: