Skip to content

Clip small linewidths in agg - #14560

Closed
timhoffm wants to merge 1 commit into
matplotlib:mainfrom
timhoffm:clip-agg-linewidth
Closed

timhoffm wants to merge 1 commit into
matplotlib:mainfrom
timhoffm:clip-agg-linewidth

Conversation

@timhoffm

Copy link
Copy Markdown
Member

PR Summary

Fixes #14498. See there for a full discussion.

Note: I've noticed that the following code uses a mixture of gc.linewidth (the original value) and linewidth (the clipped value). Can somebody with more Agg knowledge please check if that is correct?

Comment thread src/_backend_agg.h Outdated
// Too small linewidths are clipped because they require a lot of
// computation and do not make sense even with antialiasing.
// Compare github #14498.
linewidth = (linewidth < 0.01) ? 0.01 : mpl_round(linewidth);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess clipping at 1/256 would make sense because the quantization of the channels is 8bit so linewidths<1/256 (or half that? perhaps...) would be quantized to zero.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are channels in this context? I only know color channels but don't see how that could be related to linewidth.

Anyways, 0.01 causes some image comparison failures, trying 0.001 to see if that fixes it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant color channels.
With antialiasing, linewidths<1 are basically represented by setting the color channels to (linewidthreal_color) (blending with the background), but that's then quantized to 8 bits so linewidths<1/(2256) should result in nothing being drawn.

@timhoffm
timhoffm force-pushed the clip-agg-linewidth branch from ed7f647 to 514484a Compare June 17, 2019 05:35
anntzer
anntzer previously approved these changes Jun 17, 2019
@anntzer
anntzer dismissed their stale review June 17, 2019 05:43

... modulo CI

@timhoffm

timhoffm commented Jun 17, 2019 •

Copy link
Copy Markdown
Member Author

Still 44 image comparison failures for a cutoff at 0.001. Needs to be investigated, ... later.
I'm really surprised that the test suite contains code a all that triggers the cutoff. In particular, would that mean we have some performance bottlenecks builtin somewhere?

@anntzer

anntzer commented Jun 17, 2019

Copy link
Copy Markdown
Contributor

Possibly clip small linewidths to zero (i.e. don't draw them at all) instead of 0.001? just a random idea...

@timhoffm
timhoffm force-pushed the clip-agg-linewidth branch from 514484a to 82b0415 Compare July 5, 2019 00:05
@timhoffm

timhoffm commented Jul 5, 2019

Copy link
Copy Markdown
Member Author

Try forcing linewidth < 0.001 to 0.

@timhoffm

timhoffm commented Jul 7, 2019 •

Copy link
Copy Markdown
Member Author

Interestingly, forcing linewidth < 0.001 to 0 causes a lot of image comparison failures with dashed lines having slightly modified widths.

@tacaswell tacaswell added this to the v3.3.0 milestone Aug 24, 2019
@QuLogic QuLogic modified the milestones: v3.3.0, v3.4.0 May 2, 2020
@jklymak
jklymak marked this pull request as draft July 23, 2020 16:31
@timhoffm

Copy link
Copy Markdown
Member Author

Anybody can pick this up if wanted. I don't have the time to debug this for now.

@QuLogic QuLogic modified the milestones: v3.4.0, v3.5.0 Jan 21, 2021
@timhoffm timhoffm modified the milestones: v3.5.0, v3.6.0 Jul 11, 2021
@timhoffm timhoffm modified the milestones: v3.6.0, unassigned Apr 30, 2022
@story645 story645 modified the milestones: unassigned, needs sorting Oct 6, 2022
@timhoffm

Copy link
Copy Markdown
Member Author

I'm not going to follow-up on this. It's too much of an edge-case to justify for me investing more time into this. If somebody has a solution, they are welcome to contribute.

@timhoffm timhoffm closed this Sep 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Freeze when setting dashed linewidth to a close-to-zero float

5 participants