Dynamic legends

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Dynamic legends

Schindler Benjamin
Hi

I'm using dynamic legends but Legend doesn't seem to be able to handle empty
legends.
I know that I could just refuse to do an empty legend, but I still would
call this behaviour a bug:

from pylab import *
 
t = arange(0.1, 4, 0.1)
s = exp(-t)
e = 0.1*abs(randn(len(s)))
figure(1)  
l0, errlines0 = errorbar(t, s, e, fmt="bo-")            
l1, errlines1 = errorbar(t, s+1, e, fmt="ro-")            
xlabel("Distance (m)")
ylabel("Height (m)")
title("Mean and standard error as a function of distance")
legend([], [])
show()

With:

Traceback (most recent call last):
  File "test.py", line 12, in ?
    legend([], [])
  File "C:\PROGRA~1\python23\Lib\site-packages\matplotlib\pylab.py", line
2315, in legend
    ret =  gca().legend(*args, **kwargs)
  File "C:\PROGRA~1\python23\Lib\site-packages\matplotlib\axes.py", line
2044, in legend
    self.legend_ = Legend(self, handles, labels, loc, **kwargs)
  File "C:\PROGRA~1\python23\Lib\site-packages\matplotlib\legend.py", line
181, in __init__
    left, top = self.texts[-1].get_position()
IndexError: list index out of range

This shouldn't be the case - right?


-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Dynamic legends

Bugzilla from bschindler@student.ethz.ch
> Is this what you are looking for :
> legend([""], [""])
>
> - Thomas

Thanks, this works but is not really a solution. As you see (below), I have
to add the [''] to the list to prevent it from crashing. To me, this is a
workaround, not a solution. I can use it for now, but this should be fixed
in matplotlib imho

enabled_sources = [x for x in self.data if self.data[x][1] == True]
self.figure.legends = []
self.figure.legend(map(lambda x: self.data[x][0], enabled_sources),
        enabled_sources + [''], 'upper right', shadow=True)








-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Loading...