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
Draggable legend results RuntimeError and AttributeError on Mac OS 10.8.1 #1266
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'
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.
Activity
dmcdougall commentedon Sep 17, 2012
I can recreate this on 10.7.4.
mdehoon commentedon 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:
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 commentedon Dec 21, 2012
I see the same thing with OS X 10.8.2 and matplotlib 1.2.0.
michaelaye commentedon Jul 4, 2013
It works here with:
10.8.4
mpl 1.2.1
Qt4Agg
obtitus commentedon Aug 29, 2013
I believe this is a macosx backend issue. Other backends work fine, but the macosx gives the reported runtime error.
mdehoon commentedon Aug 30, 2013
AFAICT it's not a macosx backend issue, but an issue with offsetbox.py.
tacaswell commentedon Aug 30, 2013
works fine in linux 1.4.x, 2.7 and Qt4Agg.
It is pretty clearly in the macosx backend.
mdehoon commentedon 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 commentedon Aug 18, 2014
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 commentedon Mar 21, 2016
Fixed by #6178