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

Draggable legend results RuntimeError and AttributeError on Mac OS 10.8.1 #1266

Closed
sinhrks opened this issue Sep 17, 2012 · 10 comments
Closed

Comments

@sinhrks
Copy link

sinhrks commented Sep 17, 2012

Environment:

  • Python 2.7.3
  • Matplotlib 1.1.1
  • Max OS 10.8.1

Code:

In [1]: import matplotlib.pyplot as plt

In [2]: plt.bar([1, 2, 3], [2, 3, 2], label='label')
Out[2]: 
[<matplotlib.patches.Rectangle at 0x1043415d0>,
 <matplotlib.patches.Rectangle at 0x104341650>,
 <matplotlib.patches.Rectangle at 0x104341ad0>]

In [3]: l = plt.legend()

In [4]: l.draggable()
Out[4]: <matplotlib.legend.DraggableLegend at 0x10434fbd0>

Once I drag the legend, the following errors occurred. The same code works fine in Windows XP.

  File "/Users/sin/Library/Python/2.7/lib/python/site-packages/matplotlib/offsetbox.py", line 376, in get_extent_offsets
    whd_list = [c.get_extent(renderer) for c in self.get_visible_children()]
  File "/Users/sin/Library/Python/2.7/lib/python/site-packages/matplotlib/offsetbox.py", line 639, in get_extent
    "lp", self._text._fontproperties, ismath=False)
  File "/Users/sin/Library/Python/2.7/lib/python/site-packages/matplotlib/backends/backend_macosx.py", line 161, in get_text_width_height_descent
    width, height, descent = self.gc.get_text_width_height_descent(unicode(s), family, size, weight, style)
RuntimeError: CGContextRef is NULL
Traceback (most recent call last):
  File "/Users/sin/Library/Python/2.7/lib/python/site-packages/matplotlib/backend_bases.py", line 1588, in motion_notify_event
    self.callbacks.process(s, event)
  File "/Users/sin/Library/Python/2.7/lib/python/site-packages/matplotlib/cbook.py", line 262, in process
    proxy(*args, **kwargs)
  File "/Users/sin/Library/Python/2.7/lib/python/site-packages/matplotlib/cbook.py", line 188, in __call__
    return mtd(*args, **kwargs)
  File "/Users/sin/Library/Python/2.7/lib/python/site-packages/matplotlib/offsetbox.py", line 1434, in on_motion
    self.update_offset(dx, dy)
  File "/Users/sin/Library/Python/2.7/lib/python/site-packages/matplotlib/offsetbox.py", line 1504, in update_offset
    loc_in_canvas = self.offsetbox_x + dx, self.offsetbox_y + dy
AttributeError: 'DraggableLegend' object has no attribute 'offsetbox_x'
@dmcdougall
Copy link
Member

I can recreate this on 10.7.4.

@mdehoon
Copy link
Contributor

mdehoon commented Dec 12, 2012

The first problem typically occurs when trying to draw outside of the event loop. If so, then the problem may be in the design of the offsetbox.py code. This is a minimal example of this error:

from pylab import *
f = figure()
renderer = f.canvas.renderer
gc = renderer.new_gc()
Traceback (most recent call last):
File "", line 1, in
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/backends/backend_macosx.py", line 97, in new_gc
self.gc.save()
RuntimeError: CGContextRef is NULL

The gist is that the graphics context gc is not properly initialized outside of the event loop, so you cannot grab a renderer and start drawing to it.

@crogre
Copy link

crogre commented Dec 21, 2012

I see the same thing with OS X 10.8.2 and matplotlib 1.2.0.

@michaelaye
Copy link

It works here with:
10.8.4
mpl 1.2.1
Qt4Agg

@obtitus
Copy link

obtitus commented Aug 29, 2013

I believe this is a macosx backend issue. Other backends work fine, but the macosx gives the reported runtime error.

@mdehoon
Copy link
Contributor

mdehoon commented Aug 30, 2013

AFAICT it's not a macosx backend issue, but an issue with offsetbox.py.

@tacaswell
Copy link
Member

works fine in linux 1.4.x, 2.7 and Qt4Agg.

It is pretty clearly in the macosx backend.

@mdehoon
Copy link
Contributor

mdehoon commented Sep 3, 2013

The bug shows up when using the macosx backend. That does not necessarily mean that the bug is located is the macosx backend.

@tacaswell tacaswell added this to the v1.5.x milestone Aug 18, 2014
@tacaswell
Copy link
Member

This seems to be (as with blitting) an consequence of the quartz not being able to issue draw commands outside of the draw call back.

Should be linked with #1319 and #531

@mdboom
Copy link
Member

mdboom commented Mar 21, 2016

Fixed by #6178

@QuLogic QuLogic modified the milestones: 2.0 (style change major release), 2.1 (next point release) Mar 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants