matplotlib / matplotlib

matplotlib: plotting with Python
https://matplotlib.org/stable/
20.28k stars 7.65k forks source link

Mac OS X backend: <Error>: CGContextClosePath: no current point #3654

Closed lebigot closed 9 years ago

lebigot commented 10 years ago

With the Mac OS X backend, under certain conditions, I guess tons of error messages like:

Oct 17 15:47:38 weinberg.local Python[877] <Error>: CGContextClosePath: no current point.

when I move the mouse inside a slider and when the figure is first drawn (it contains many plots). The TkAgg backend does not report any problem.

This slows down considerably the interaction with the slider.

The code is currently complex, so sharing it here is not obvious: are there tests, changes, etc. that I could run so as to try to nail down the problem?

tacaswell commented 10 years ago

what version of mpl?

cc @mdehoon

lebigot commented 10 years ago

That's for version 1.4.0.

tacaswell commented 10 years ago

The string CGContextClosePath only shows up two places in the code, in _draw_path and in quadmesh drawing. From your comment I am assuming the problem is in the first (https://github.com/matplotlib/matplotlib/blob/master/src/_macosx.m#L265). The cr object looks to be one of these things (https://developer.apple.com/library/mac/documentation/GraphicsImaging/Reference/CGContext/index.html). I suspect that there needs to be some sanity checking on cr prior to the call ot CGClosePath.

I don't have a mac to test any of these theories on....

This looks relevant: http://www.finetunedmac.com/forums/ubbthreads.php?ubb=showflat&Number=26496

mdehoon commented 10 years ago

@lebigot Can you check the sequence of codes in _draw_path ? I am wondering if the sequence of codes is incorrect (then the bug is upstream), or the sequence of codes is correct, but _draw_path misinterprets them.

lebigot commented 10 years ago

Two points:

This points to the quadmesh code being the culprit.

@mdehoon I am not sure how to perform the check you mentioned: it would take someone more versed into Matplolib's internals. :) I am currently failing to reproduce the problem, but I am not sure under which exact conditions I had it…

mdehoon commented 9 years ago

Are you able to replicate the bug?

lebigot commented 9 years ago

I tried, but failed to replicate the bug. It happened while running on data that I don't have at hand anymore.

That said, I have seen it many times before in other projects of mine, so next time I'll try to post something more specific if it happens again.

lebigot commented 9 years ago

I just found a simple way of replicating the error, that might have been the original way that triggered it:

>>> pyplot.bar([0, 1], [1, float("nan")])
Dec 31 15:55:42 weinberg.local Python[12859] <Error>: CGContextClosePath: no current point.

Granted, it is strange to use nan here, but a more instructive warning would be great.

mdehoon commented 9 years ago

OK I get the same error message with your example. Can you change line 265 in src/_macosx.m from

            CGContextClosePath(cr);

to

            if (n > 0) CGContextClosePath(cr);

and make sure the error message doesn't appear? It would be great if you could run the test suite to make sure this doesn't introduce new bugs.

lebigot commented 9 years ago

I never compiled Matplotlib (MacPorts!) and I will unfortunately not be able to do this right now…

PS: It's great that you have some idea for the fix. :)

tacaswell commented 9 years ago

@mdehoon Can you put in a PR with that patch?

tacaswell commented 9 years ago

Closed by #4006