Skip to content

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

Description

@sinhrks

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'

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions