You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Freeze when setting dashed linewidth to a close-to-zero float #14498
Looks like something wrong with Agg... Likely we should investigate the lowest value Agg can draw properly and clip linewidths in the backend_agg graphicscontext?
Turns out, small linewidths require a lot of computation. When running the above code with different linewidths, the plot window appears, but is black for a certian time. During that time CPU usage is at 100%. Computation time goes up very strongly when reducing the linewidth:
lw=1e-4 # ~1s
lw=1e-5 # ~6s
lw=1e-6 # ~54s
Further notes:
the delay is caused by antialiasing (setting rcParams['lines.antialiased'] = False results in immediate draw). Edit: Just saw that without antialiasing, the linewidth is already clipped (_backend_agg.h ll.407):
with lw=1e-3 the initial draw is not noticably slower, however, resizing already feels a bit laggy.
for values lw=1e-2 and smaller, no visible line is drawn at all.
What to do?
From a practical point of view everything equal or smaller than lw=1e-2 is identical (not drawn). I also don't think there are practical purposes for lines smaller than 1e-2 points. It should therefore be safe to clip lw to 1e-2.
I wonder if this is also partly dependent upon the figure's dpi setting? If
so, then a straight-up clipping of 1e-2 is not sufficient as at high dpi,
it might still be visible, perhaps?
On Sun, Jun 16, 2019 at 2:29 PM Tim Hoffmann ***@***.***> wrote:
Turns out, small linewidths require a lot of computation. When running the
above code with different linewidths, the plot window appears, but is black
for a certian time. During that time CPU usage is at 100%. Computation time
goes up very strongly when reducing the linewidth:
lw=1e-4 # ~1s
lw=1e-5 # ~6s
lw=1e-6 # ~54s
Further notes:
- the delay is caused by antialiasing (setting rcParams['lines.antialiased']
= False results in immediate draw).
- resizing the plot also lags for small linewidths.
- with lw=1e-3 the initial draw is not noticably slower, however,
resizing already feels a bit laggy.
- for values lw=1e-2 and smaller, no visible line is drawn at all.
What to do?
From a practical point of view everything equal or smaller than lw=1e-2
is identical (not drawn). I also don't think there are practical purposes
for lines smaller than 1e-2 points. It should therefore be safe to clip lw
to 1e-2.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#14498?email_source=notifications&email_token=AACHF6BJJGCDVS5OHJIIUZ3P22BCFA5CNFSM4HWHWOAKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODXZSSAI#issuecomment-502475009>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AACHF6F2HYCNWUADKPE33FTP22BCFANCNFSM4HWHWOAA>
.
It seems to have to do with antialiasing. But not an expert in the field, I neither know what type of antialiasing agg is using, nor how thin lines affect the performance of antialiasing.
I don't think thin lines are per se computationally more expensive than thick lines; it's just that dashed lines have more dashes the smaller their width. I.e. the number of dashes per unit length, and hence the number of points the renderer needs to draw, grows because there is a fixed dash-length to width ratio.
Adding an additional safety factor of 2 or 4 for hi-dpi should be enough, I mean how high can hi-dpi be compared to a standard resolution? If you are really concerned still, one could make that cutoff configurable, either in rcParams or in some global variable. That way users with extreme needs would still be able to draw any dashing correctly.
changed the title [-]Freeze when setting pyplot linewidth to a close-to-zero float[/-][+]Freeze when setting dashed linewidth to a close-to-zero float[/+]on Jul 8, 2019
I first encountered it in the Jupyter notebook environment and then replicated it in IPython. The window becomes unresponsive and my laptop fans kick in so I had to end the process.
I am using Python 3.7.3, matplotlib 3.1.1, Qt5Agg backend, and Linux Mint 19.1.
Activity
anntzer commentedon Jun 10, 2019
Looks like something wrong with Agg... Likely we should investigate the lowest value Agg can draw properly and clip linewidths in the backend_agg graphicscontext?
timhoffm commentedon Jun 16, 2019
Turns out, small linewidths require a lot of computation. When running the above code with different linewidths, the plot window appears, but is black for a certian time. During that time CPU usage is at 100%. Computation time goes up very strongly when reducing the linewidth:
Further notes:
the delay is caused by antialiasing (setting.rcParams['lines.antialiased'] = Falseresults in immediate draw)Edit: Just saw that without antialiasing, the linewidth is already clipped (_backend_agg.h ll.407):
lw=1e-3the initial draw is not noticably slower, however, resizing already feels a bit laggy.lw=1e-2and smaller, no visible line is drawn at all.What to do?
From a practical point of view everything equal or smaller than
lw=1e-2is identical (not drawn). I also don't think there are practical purposes for lines smaller than 1e-2 points. It should therefore be safe to cliplwto 1e-2.WeatherGod commentedon Jun 17, 2019
timhoffm commentedon Jun 17, 2019
Even 1e-3 is not sufficient for our test cases. See #14560. Needs more investigation.
tacaswell commentedon Jul 7, 2019
Why are thin lines computationally expensive?
timhoffm commentedon Jul 7, 2019
It seems to have to do with antialiasing. But not an expert in the field, I neither know what type of antialiasing agg is using, nor how thin lines affect the performance of antialiasing.
ImportanceOfBeingErnest commentedon Jul 7, 2019
I don't think thin lines are per se computationally more expensive than thick lines; it's just that dashed lines have more dashes the smaller their width. I.e. the number of dashes per unit length, and hence the number of points the renderer needs to draw, grows because there is a fixed dash-length to width ratio.
timhoffm commentedon Jul 8, 2019
@ImportanceOfBeingErnest 👍 That explains it. Non-antialiased lines are clipped to a width >= 0.5
matplotlib/src/_backend_agg.h
Line 408 in db90685
so they do not suffer from the increased number of points for small widths and thus do not have a performance issue.
jklymak commentedon Jul 8, 2019
So can we just clip the dash length?
tacaswell commentedon Jul 8, 2019
Sigh, the dash scaling is one of those rabbit holes with a 🐲 at the bottom.
We talked about clipping that scaling, but decided not to due to concerns about negatively affecting hi-dpi outputs.
attn @dopplershift as I recall you were the most vocal on not clipping the dash scaling in the run up to 2.0.
timhoffm commentedon Jul 8, 2019
Adding an additional safety factor of 2 or 4 for hi-dpi should be enough, I mean how high can hi-dpi be compared to a standard resolution? If you are really concerned still, one could make that cutoff configurable, either in rcParams or in some global variable. That way users with extreme needs would still be able to draw any dashing correctly.
jklymak commentedon Jul 8, 2019
I agree. How high can hi dpi go? Are there really practical uses to 10,000 dpi?
[-]Freeze when setting pyplot linewidth to a close-to-zero float[/-][+]Freeze when setting dashed linewidth to a close-to-zero float[/+]4 remaining items
jwuphysics commentedon Jun 26, 2020
I get a similar freeze when trying to set
dashes=(0, 0), e.g.,I first encountered it in the Jupyter notebook environment and then replicated it in IPython. The window becomes unresponsive and my laptop fans kick in so I had to end the process.
I am using Python 3.7.3, matplotlib 3.1.1, Qt5Agg backend, and Linux Mint 19.1.
oscargus commentedon Mar 4, 2022
This part is fixed with #22569