MatplotLib Figure Legends

Any more hints?

Make that

        l = Legend(self, handles, labels, loc)

Should work - let me know if you have any more troubles.

JDH

Thanks John...i did actually try that before i sent my
previous email...sorry that the error messages were buried
under a bunch of other stuff. I did have a problem after
i added the self. Here is what i get (my hacked up legendDemp.py follows
the error messages):

floyd:/home/jbenson/python>python legendDemo.py
Traceback (most recent call last):
  File "legendDemo.py", line 30, in ?
    'upper left')
  File "/usr/local/lib/python2.3/site-packages/matplotlib/figure.py", line
179, in legend
    l = Legend(self, handles, labels, loc)
  File "/usr/local/lib/python2.3/site-packages/matplotlib/legend.py", line
107, in __init__
    self._texts = self._get_texts(labels, textleft, upper)
  File "/usr/local/lib/python2.3/site-packages/matplotlib/legend.py", line
215, in _get_texts
    HEIGHT = self._approx_text_height()
  File "/usr/local/lib/python2.3/site-packages/matplotlib/legend.py", line
126, in _approx_text_height
    return
self.FONTSIZE/72.0*self.figure.dpi.get()/self.parent.bbox.height()
AttributeError: 'NoneType' object has no attribute 'dpi'
floyd:/home/jbenson/python>
                                                   
# legendDemo.py
                                                            
from matplotlib.matlab import *
                                                                                                           
a = arange(0,3,.02)
b = arange(0,3,.02)
c=exp(a)
d=c.tolist()
d.reverse()
d = array(d)
                                                                                                           
ax = subplot(111)
lines = plot(a,c,'k--',a,d,'k:',a,c+d,'k')
                                                                                                           
bNotHacked = False
                                                                                                           
if bNotHacked:
                                                                                                           
    legend(('Model length', 'Data length', 'Total message length'), 'upper
left')
                                                                                                           
else:
                                                                                                           
    fig = gcf()
                                                                                                           
    line1 = lines[0]
    line2 = lines[1]
    line3 = lines[2]
                                                                                                           
    fig.legend((line1, line2, line3),
               ('Model length', 'Data length', 'Total message length'),
               'upper left')
                                                                                                           
ax.set_ylim([-1,20])
ax.grid(0)
xlabel('Model complexity --->')
ylabel('Message length --->')
title('Minimum Message Length')
set(gca(), 'yticklabels', [])
set(gca(), 'xticklabels', [])
                                                                                                           
savefig('legend_demo_small', dpi=60)
savefig('legend_demo_large', dpi=120)
                                                                                                           
show()

···

On Sat, 3 Jul 2004, John Hunter wrote:

Make that

        l = Legend(self, handles, labels, loc)

Should work - let me know if you have any more troubles.

~

Jim