Skip to content

"Artifact" when plotting labels with outline=True #252

Closed

Description

@clwgg

I've come across a weird "artifact" that can be triggered when plotting labels with outline=True:

sdata.pl.render_labels(outline=False).pl.show()

main-1

sdata.pl.render_labels(outline=True).pl.show()

main-2

It's a little hard to see, but in the 2nd figure, there appears to be some kind of "shade" in the top-left corner of the plot.

I went digging a bit for possible causes -- please see the PR linked below for a potential fix.

Activity

  1. timtreis commented on Aug 26, 2024

    @timtreis
    Member

    Hey @clwgg,

    sorry for the late response! I think the "shade" you're seeing is some improperly transformed data layer, probably a difference in scale?

    Could you try to reproduce your error with the code from #323? I've included several fixes to render_labels there, amongst which I also changed the outline logic to be purely based on outline_alpha since 0/1 there would be equivalent to outline = True/False

  2. clwgg commented on Aug 28, 2024

    @clwgg
    Author

    Hi @timtreis! I'm happy to report that I don't observe the artifact anymore with the current main.

    It also appears to fix the other observations I had over at #253, except for the use case of plotting labels without alpha at all (render_labels(outline_alpha=1.0, fill_alpha=1.0)), but I see you're already fixing that elsewhere, so I believe both this issue, as well as my PR (and possibly the other issue I linked in the PR) can be closed! 🎉

  3. linked a pull request that will close this issueRefactor of labels logic #336on Aug 28, 2024
  4. timtreis commented on Aug 28, 2024

    @timtreis
    Member

    Hey @clwgg,

    happy to hear that the issue is already partially solved!

    Could you elaborate on

    except for the use case of plotting labels without alpha at all (render_labels(outline_alpha=1.0, fill_alpha=1.0)

    With the current code, this would be equivalent to render_labels(fill_alpha=1.0) since any border would only ever be inside the label anyway. I just found that out like a minute ago, but here's the comment I added for clarification:
    image

  5. clwgg commented on Aug 28, 2024

    @clwgg
    Author

    hmm, that's a fair point! I suppose it depends on what we think the zorder of a labels' fill and outline should be. AFAIK, in a matplotlib scatterplot for example, the outline of a marker is drawn on top of the fill, so in a case without any transparency, I would expect to still see the outline on top of the fill, even if it's fully contained within the label.

  6. timtreis commented on Aug 28, 2024

    @timtreis
    Member

    image

    This would be the output if we don't just skip the outline when the alphas are the same. Because they're overlayed, they add up, in this case to fully opaque. Would you use it to for example generate a plot like this where the borders are darker but still not opaque?
    image

  7. timtreis commented on Aug 28, 2024

    @timtreis
    Member

    image
    Without any alpha you theoretically still see the border but I think that's just an artifact from the resolution of the plot.

  8. clwgg commented on Aug 28, 2024

    @clwgg
    Author

    Interesting! To be honest, the main use case I'm envisioning is if I was coloring the labels based on some continuous variable and didn't want to use transparency (maybe to increase contrast), but still would like the individual labels to be distinguishable by adding an outline, similar to the fourth image in the PR I linked above, or something like
    this.

    But I can see that allowing this opens potential cans of worms, especially in combination with contour_px, and I suppose one could still force a similar behaviour with something like render_labels(outline_alpha=1.0, fill_alpha=.99)...

  9. timtreis commented on Aug 29, 2024

    @timtreis
    Member

    You could theoretically just call render_labels twice to enable that usecase:

    image

  10. clwgg commented on Aug 29, 2024

    @clwgg
    Author

    good point, thanks! 👍

  11. timtreis commented on Aug 29, 2024

    @timtreis
    Member

    Seems to be solved :) Thanks @clwgg !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions