Feature request: make labels accept non-string arguments

Hi folks,

I am working on a software package to manipulate spectra and bandpasses, and I expect my users will use it hand in hand with the pylabe interface of matplotlib in order to see the results of their manipulations.

It would be extremely useful if xlabel, ylabel, title, and possibly legend could be made smart enough to attempt to call a __str__ method on the objects they are passed, so that xlabel(MyObject) behaves as intelligently as "print MyObject" does.

For example, here's what happens presently:

>>> bb=S.BlackBody(33000)
>>> plot(bb.wave,bb.flux)
>>> print bb.waveunits
angstrom
>>> xlabel(bb.waveunits)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/stsci/pyssgdev/2.5/matplotlib/pylab.py", line 1069, in xlabel
l = gca().set_xlabel(s, *args, **kwargs)
File "/usr/stsci/pyssgdev/2.5/matplotlib/axes.py", line 1874, in set_xlabel
label.set_text(xlabel)
File "/usr/stsci/pyssgdev/2.5/matplotlib/text.py", line 735, in set_text
raise TypeError("This doesn't look like a string: '%s'"%s)
TypeError: This doesn't look like a string: 'angstrom'

It seems to me these functions shouldn't care whether they're given a string or not, as long as the things they are given know how to make strings out of themselves.

Of course, the workaround is for me to type
xlabel(str(bb.waveunits))

but in addition to the annoyance of extra typing, most of my intended users are not presently Python users, and the present behavior (especially the error given at the end of the traceback!) will confuse them.

Any chance of getting this implemented?

Hopefully,
Vicki Laidler, STScI

Victoria G. Laidler wrote:
[...]

It would be extremely useful if xlabel, ylabel, title, and possibly legend could be made smart enough to attempt to call a __str__ method on the objects they are passed, so that xlabel(MyObject) behaves as intelligently as "print MyObject" does.

[...]

Any chance of getting this implemented?

Vicki,

Done in svn.

Eric

···

Hopefully,
Vicki Laidler, STScI

Thanks!! I really appreciate the fast action!

Vicki

Eric Firing wrote:

···

Victoria G. Laidler wrote:
[...]

It would be extremely useful if xlabel, ylabel, title, and possibly legend could be made smart enough to attempt to call a __str__ method on the objects they are passed, so that xlabel(MyObject) behaves as intelligently as "print MyObject" does.

[...]

Any chance of getting this implemented?

Vicki,

Done in svn.

Eric

Hopefully,
Vicki Laidler, STScI