Legends don't work in the polar plot.

Has anyone tried to put a legend in a polar plot? I get an

    > error whenever I try this. To reproduce the error, run the
    > polar plot demo and then do something like:

    > legend( ( "test" ) )
    > "/group/monte/development/rhe3/tools.0504/lib/python2.4/site-packages/matplotlib/axes.py",
    > line 1869, in get_handles handles.extend(self.patches)
    > AttributeError: PolarAxes instance has no attribute 'patches'

    > Should I file this as a bug? Thanks, Ted Ted Drain Jet

Maybe a feature request? The problem is deeper than simply adding the
missing patches attr (which holds a list of patches stored by the
axes). If you add that (as I just did), you can run legend w/ no
traceback but no legend either. I think the problem is that the
legend by default uses the axes coordinate system to place the
rectangle in which the legend resides is being placed in axes
coordinates, and the axes coordinate system for polar axes is not the
same as for rectangular axes and this is fouling up the legend
placement.

There is a workaround using figlegend

  >>> lines = polar(range(10))
  >>> figlegend(lines, ('my label',), 'upper right')

I think it would be nice for polar axes legend to work automagically,
so you might want to add this as a feature request on the sf site. I
already fixed the patch/traceback crash, but now it just fails
silently (no legend, no error). I think I'll add an PolarAxes legend
NotImplementedError which raises an exceptions and suggests figlegend
for the time being.

I'm sure there are other surprises one will find when trying to use
some of the Axes parent methods (eg table) in the PolarAxes. It
would be nice if these were also indicated with NotImplementedError
until they are. We can fill these in as we find them.

JDH

Thanks for the tip - figlegend works just fine for my application. I'll file an enhancement for tracking purposes...

Ted

···

At 07:29 AM 5/12/2005, John Hunter wrote:

    > Has anyone tried to put a legend in a polar plot? I get an
    > error whenever I try this. To reproduce the error, run the
    > polar plot demo and then do something like:

    > legend( ( "test" ) )
    > "/group/monte/development/rhe3/tools.0504/lib/python2.4/site-packages/matplotlib/axes.py",
    > line 1869, in get_handles handles.extend(self.patches)
    > AttributeError: PolarAxes instance has no attribute 'patches'

    > Should I file this as a bug? Thanks, Ted Ted Drain Jet

Maybe a feature request? The problem is deeper than simply adding the
missing patches attr (which holds a list of patches stored by the
axes). If you add that (as I just did), you can run legend w/ no
traceback but no legend either. I think the problem is that the
legend by default uses the axes coordinate system to place the
rectangle in which the legend resides is being placed in axes
coordinates, and the axes coordinate system for polar axes is not the
same as for rectangular axes and this is fouling up the legend
placement.

There is a workaround using figlegend

  >>> lines = polar(range(10))
  >>> figlegend(lines, ('my label',), 'upper right')

I think it would be nice for polar axes legend to work automagically,
so you might want to add this as a feature request on the sf site. I
already fixed the patch/traceback crash, but now it just fails
silently (no legend, no error). I think I'll add an PolarAxes legend
NotImplementedError which raises an exceptions and suggests figlegend
for the time being.

I'm sure there are other surprises one will find when trying to use
some of the Axes parent methods (eg table) in the PolarAxes. It
would be nice if these were also indicated with NotImplementedError
until they are. We can fill these in as we find them.

JDH