Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plt.annotate(): segmentation fault when coordinates are too high #6984

Closed
3 tasks done
FilipDominec opened this issue Aug 26, 2016 · 5 comments
Closed
3 tasks done

plt.annotate(): segmentation fault when coordinates are too high #6984

FilipDominec opened this issue Aug 26, 2016 · 5 comments

Comments

@FilipDominec
Copy link

FilipDominec commented Aug 26, 2016

  • Matplotlib version 1.5.1-1ubuntu1, Python version2.7.12, Platform Ubuntu 16.04 x64
  • I installed Matplotlib and Python from apt repository
  • Example:
#!/usr/bin/env python
import matplotlib.pyplot as plt
plt.annotate('blah',  xy      = (1e6, 1),  xycoords  ='data')  ## 1e6 or more causes the crash.
#plt.xlim((0, 2e12))                                       ## does not help
plt.savefig("output.png", bbox_inches='tight')

Returns:

filip@comp:/tmp/$ python a.py 
Segmentation fault (core dumped)

A workaround is to establish the plot limits before the use the plt.annotate(), and call the command conditionally only if it fits into the view. But this surely is not the way Matplotlib should work (and localizing this source of crashes also took quite a long time, since the corresponding code was embedded in a 2000-line simulation script that worked until today).

FilipDominec added a commit to FilipDominec/python-meep-utils that referenced this issue Aug 26, 2016
@tacaswell
Copy link
Member

The segfault is fixed in 604e06e (and backported to 1.5.x as 84f3a6f ). Trying to make too-big figures now raises instead of segfaulting.

If I set the limit (on current master) I can not reproduce the issue with master or 1.5.1.

There are a couple of overlapping issues here:

  • by default the Annotation artists are not clipped to the axis
  • you are using bbox_inches='tight' which resizes the figure to fit all of the artists

As a work around I suggest either passing clip_on=True to annotate or not using bbox_layout='tight'.

Closing this as the segfault is fixed and the other behavior is correct (if annoying).

@FilipDominec
Copy link
Author

OK, thank you.

@tacaswell
Copy link
Member

Your welcome, sorry I do not have a better answer for you.

@WeatherGod
Copy link
Member

I noticed your initial statement " it also takes quite a long time to
establish which part of 2000-line simulation script causes the segfault"

A really useful tool that is now in the standard library is "faulthandler":
https://docs.python.org/3/library/faulthandler.html#example

It has saved me lots of time when I used to just add print statements
everywhere to find the fault.

On Mon, Aug 29, 2016 at 8:07 AM, Thomas A Caswell notifications@github.com
wrote:

Your welcome, sorry I do not have a better answer for you.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#6984 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AARy-E-i6x68W-rQeqkQp2MTdczxx3-Bks5qksuNgaJpZM4JuMUa
.

@FilipDominec
Copy link
Author

@WeatherGod Excellent tip! I believed that there is no way to get any info on segfaults when they happen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants