From: Jim B. <jb...@se...> - 2004-07-01 21:37:53
|
Hi John, Today i finally got around to trying a suggestion that you made on May 22...on how to put a legend on a Figure (outside of the axis). So i hacked up the example legendDemo.py to experiment with: # Haked up legendDemp.py # Thanks to Charles Twardy for this example 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') #legend(('Model length', 'Data length', 'Total message length'), 'upper left') 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() # End of: Haked up legendDemp.py I then go the following error: clavius:/home/jbenson/python>python legendDemo.py Traceback (most recent call last): File "legendDemo.py", line 22, in ? 'upper left') File "/usr/local/lib/python2.3/site-packages/matplotlib/figure.py", line 179, in legend l = Legend(handles, labels, loc) TypeError: __init__() takes exactly 5 arguments (4 given) clavius:/home/jbenson/python> Should that line 179 in figure.py be: l = Legend(self, handles, labels, loc) # -added ->self<- ? Just for fun, i tried that change and re-ran: clavius:/home/jbenson/python>python legendDemo.py Traceback (most recent call last): File "legendDemo.py", line 22, 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' clavius:/home/jbenson/python> ...so those errors look worse. (i'm using matplotlib-0.54.2) Any more hints? Thanks, Jim |