Ryan May wrote:
Neal Becker wrote:
What's wrong here?
This code snippet:
from pylab import plot, show
plot (Id, pout)
['50', '100', '150', '200', '250', '300', '350', '400', '450', '500', '550',
'600', '650', '700', '750', '800', '850', '900', '950', '1000', '1050']
['0', '7.4', '11.4', '14.2', '16.3', '18.1', '19.3', '20.6', '21.6', '22.6',
'23.4', '24.1', '24.9', '25.4', '26.1', '26.5', '26.9', '27.1', '27.3',
The problem here is that you're trying to plot lists of strings instead of lists
of numbers. You need to convert all of these values to numbers. However,
matplotlib could behave a bit more nicely in this case rather than simply
recursing until it hits the limit.
Ok, my debugging tells me the problem comes down to the units support,
specifically this code starting at line 130 in units.py:
if converter is None and iterable(x):
# if this is anything but an object array, we'll assume
# there are no custom units
if isinstance(x, np.ndarray) and x.dtype != np.object:
for thisx in x:
converter = self.get_converter( thisx )
Because a string is iterable, and even a single character is considered iterable,
this code recurses forever. I can think this can be solved by, in addition to
the iterable() check, make sure that x is not string like. If it is, this will
return None as the converter. Somehow, this actually will then plot properly.
I'm still trying to run down why this works, but I'm running out of time for the
day. I will say that the data set for the line2D object is indeed a masked array
of dtype ('|S4').
Anyone object to adding the check?
In addition, why are we looping over thisx in x but returning inside the loop?
Wouldn't this *always* be the same as x?
Graduate Research Assistant
School of Meteorology
University of Oklahoma