Description
I've run into a problem drawing plots with dashed or dotted lines that extend out to many times the size of the plot area. This SSCCE demonstrates the issue on my system:
import matplotlib
matplotlib.use('macosx')
import matplotlib.pyplot as plt
line_ymax = 1e6
plot_ymax = 2
plt.plot([0, 0], [1, line_ymax], linestyle='dotted')
plt.ylim(0, plot_ymax)
plt.show()
I instrumented this with a bit of timing code and found that the call to plt.show()
takes about 13 seconds on my machine, during which the Python process is using 100% CPU. Playing with the values shows that the time taken by show()
seems to be asymptotically linear in line_ymax / plot_ymax
. Changing the line style to 'dashed'
reduces the time by a factor of 2.5-3, while changing it to 'solid'
makes the problem go away entirely. (I suppose this suggests something may be linear in the number of separate line segments being drawn.)
I also ran the code with line tracing enabled (python -m trace -t hang-mwe.py
) and identified the specific line that hangs (or at least, the last line to be printed before the trace output pauses):
path.py(260): return self._simplify_threshold
A larger context from this run is attached in trace.txt, in case it helps; look around line 421.
The problem does not occur in the webagg backend. I also tried swapping in other backends (agg, cairo, pdf, pgf, ps, svg, template - all the options that didn't give an error) for good measure, but none of them displayed anything (though neither did they have any noticeable "hang time").
I found the issue on OS X El Capitan using Matplotlib 1.5.1rc1 and Python 3.4.4, both installed through MacPorts. It goes back at least as far as 1.4.0 (the earliest version I could compile) and is still present in the current master branch (196f344).