Revision: 6166 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6166&view=rev Author: jdh2358 Date: 2008年10月07日 15:13:53 +0000 (2008年10月07日) Log Message: ----------- added michaels unit detection optimization for arrays Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/units.py Modified: trunk/matplotlib/lib/matplotlib/units.py =================================================================== --- trunk/matplotlib/lib/matplotlib/units.py 2008年10月07日 15:13:13 UTC (rev 6165) +++ trunk/matplotlib/lib/matplotlib/units.py 2008年10月07日 15:13:53 UTC (rev 6166) @@ -135,7 +135,7 @@ for thisx in x: converter = self.get_converter( thisx ) - if converter: break + return converter #DISABLED self._cached[idx] = converter return converter This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 6165 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6165&view=rev Author: jdh2358 Date: 2008年10月07日 15:13:13 +0000 (2008年10月07日) Log Message: ----------- added michaels unit detection optimization for arrays Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/units.py Modified: trunk/matplotlib/lib/matplotlib/units.py =================================================================== --- trunk/matplotlib/lib/matplotlib/units.py 2008年10月07日 06:31:29 UTC (rev 6164) +++ trunk/matplotlib/lib/matplotlib/units.py 2008年10月07日 15:13:13 UTC (rev 6165) @@ -43,6 +43,7 @@ units.registry[datetime.date] = DateConverter() """ +import numpy as np from matplotlib.cbook import iterable, is_numlike class AxisInfo: @@ -127,6 +128,11 @@ converter = self.get(classx) 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: + return None + for thisx in x: converter = self.get_converter( thisx ) if converter: break This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 6924 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6924&view=rev Author: efiring Date: 2009年02月21日 20:14:08 +0000 (2009年2月21日) Log Message: ----------- Add new axis arguments to units.py docstring Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/units.py Modified: trunk/matplotlib/lib/matplotlib/units.py =================================================================== --- trunk/matplotlib/lib/matplotlib/units.py 2009年02月21日 19:06:58 UTC (rev 6923) +++ trunk/matplotlib/lib/matplotlib/units.py 2009年02月21日 20:14:08 UTC (rev 6924) @@ -19,12 +19,12 @@ class DateConverter(units.ConversionInterface): @staticmethod - def convert(value, unit): + def convert(value, unit, axis): 'convert value to a scalar or array' return dates.date2num(value) @staticmethod - def axisinfo(unit): + def axisinfo(unit, axis): 'return major and minor tick locators and formatters' if unit!='date': return None majloc = dates.AutoDateLocator() @@ -34,7 +34,7 @@ label='date') @staticmethod - def default_units(x): + def default_units(x, axis): 'return the default unit for x or None' return 'date' This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 7905 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7905&view=rev Author: jrevans Date: 2009年10月23日 17:44:29 +0000 (2009年10月23日) Log Message: ----------- Changed the algorithm that determines what converter to use for unitized data to allow for strings and numpy arrays of types other than 'object'. The new algorithm takes into account the possibility of infinite recursion for strings or any other type. Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/units.py Modified: trunk/matplotlib/lib/matplotlib/units.py =================================================================== --- trunk/matplotlib/lib/matplotlib/units.py 2009年10月23日 16:43:08 UTC (rev 7904) +++ trunk/matplotlib/lib/matplotlib/units.py 2009年10月23日 17:44:29 UTC (rev 7905) @@ -128,18 +128,14 @@ if classx is not None: converter = self.get(classx) - # Check explicity for strings here because they would otherwise - # lead to an infinite recursion, because a single character will - # pass the iterable() check. - if converter is None and iterable(x) and not is_string_like(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: - return None - + if converter is None and iterable(x): for thisx in x: - converter = self.get_converter( thisx ) - return converter + # Make sure that recursing might actually lead to a solution, if + # we are just going to re-examine another item of the same kind, + # then do not look at it. + if classx and classx != getattr(thisx, '__class__', None): + converter = self.get_converter( thisx ) + return converter #DISABLED self._cached[idx] = converter return converter This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
This isn't quite what I was suggesting (and seems to be equivalent to the code as before). In the common case where there are no units in the data, this will still traverse the entire list. I think replacing the whole loop with: converter = self.get_converter(iter(x).next()) would be even better. (Since lists of data should not be heterogeneous anyway...) Mike jd...@us... wrote: > Revision: 6166 > http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6166&view=rev > Author: jdh2358 > Date: 2008年10月07日 15:13:53 +0000 (2008年10月07日) > > Log Message: > ----------- > added michaels unit detection optimization for arrays > > Modified Paths: > -------------- > trunk/matplotlib/lib/matplotlib/units.py > > Modified: trunk/matplotlib/lib/matplotlib/units.py > =================================================================== > --- trunk/matplotlib/lib/matplotlib/units.py 2008年10月07日 15:13:13 UTC (rev 6165) > +++ trunk/matplotlib/lib/matplotlib/units.py 2008年10月07日 15:13:53 UTC (rev 6166) > @@ -135,7 +135,7 @@ > > for thisx in x: > converter = self.get_converter( thisx ) > - if converter: break > + return converter > > #DISABLED self._cached[idx] = converter > return converter > > > This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. > > ------------------------------------------------------------------------- > This SF.Net email is sponsored by the Moblin Your Move Developer's challenge > Build the coolest Linux based applications with Moblin SDK & win great prizes > Grand prize is a trip for two to an Open Source event anywhere in the world > http://moblin-contest.org/redirect.php?banner_id=100&url=/ > _______________________________________________ > Matplotlib-checkins mailing list > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins > -- Michael Droettboom Science Software Branch Operations and Engineering Division Space Telescope Science Institute Operated by AURA for NASA
Sorry. I didn't read carefully enough. That's right -- the "if converter: break" was replaced with "return converter". You're right. This is fine. Mike John Hunter wrote: > On Tue, Oct 7, 2008 at 11:26 AM, Michael Droettboom <md...@st...> wrote: > >> This isn't quite what I was suggesting (and seems to be equivalent to >> the code as before). In the common case where there are no units in the >> data, this will still traverse the entire list. >> >> I think replacing the whole loop with: >> >> converter = self.get_converter(iter(x).next()) >> >> would be even better. (Since lists of data should not be heterogeneous >> anyway...) >> > > Hmm, I don't see how it would traverse the entire list > > for thisx in x: > converter = self.get_converter( thisx ) > return converter > > since it will return after the first element in the loop. I have no > problem with the iter approach, but am not seeing what the problem is > with this usage. > > JDH > -- Michael Droettboom Science Software Branch Operations and Engineering Division Space Telescope Science Institute Operated by AURA for NASA