Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0f17bd2

Browse files
author
James Evans
committed
hanged the order of arguments for unit.ConverterInterface class.
svn path=/trunk/matplotlib/; revision=6849
1 parent e391bc4 commit 0f17bd2

4 files changed

Lines changed: 44 additions & 40 deletions

File tree

examples/units/basic_units.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ class TaggedValue (object):
9898
'__sub__':ConvertAllProxy,
9999
'__mul__':ConvertAllProxy,
100100
'__rmul__':ConvertAllProxy,
101+
'__cmp__':ConvertAllProxy,
102+
'__lt__':ConvertAllProxy,
103+
'__gt__':ConvertAllProxy,
101104
'__len__':PassThroughProxy}
102105

103106
def __new__(cls, value, unit):
@@ -228,7 +231,7 @@ def get_conversion_fn(self, unit):
228231
return self.conversions[unit]
229232

230233
def convert_value_to(self, value, unit):
231-
#print 'convert value to: value ="%s", unit="%s"'%(value, type(unit)), self.conversions
234+
#print 'convert value to: value ="%s", unit="%s"'%(value, type(unit)), self.conversions
232235
conversion_fn = self.conversions[unit]
233236
ret = conversion_fn(value)
234237
return ret

lib/matplotlib/axis.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,7 @@ def update_units(self, data):
939939
converter = munits.registry.get_converter(data)
940940
if converter is None: return False
941941
self.converter = converter
942-
default = self.converter.default_units(self, data)
942+
default = self.converter.default_units(data, self)
943943
#print 'update units: default="%s", units=%s"'%(default, self.units)
944944
if default is not None and self.units is None:
945945
self.set_units(default)
@@ -955,7 +955,7 @@ def _update_axisinfo(self):
955955
if self.converter is None:
956956
return
957957

958-
info = self.converter.axisinfo(self, self.units)
958+
info = self.converter.axisinfo(self.units, self)
959959
if info is None:
960960
return
961961
if info.majloc is not None and self.major.locator!=info.majloc:
@@ -982,7 +982,7 @@ def convert_units(self, x):
982982
#print 'convert_units returning identity: units=%s, converter=%s'%(self.units, self.converter)
983983
return x
984984

985-
ret = self.converter.convert(self, x, self.units)
985+
ret = self.converter.convert(x, self.units, self)
986986
#print 'convert_units converting: axis=%s, units=%s, converter=%s, in=%s, out=%s'%(self, self.units, self.converter, x, ret)
987987
return ret
988988

lib/matplotlib/dates.py

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,51 +1007,52 @@ class DateConverter(units.ConversionInterface):
10071007
"""The units are equivalent to the timezone."""
10081008

10091009
@staticmethod
1010-
def axisinfo(axis, unit):
1010+
def axisinfo(unit, axis):
10111011
'return the unit AxisInfo'
10121012
# make sure that the axis does not start at 0
1013-
ax = axis.axes
1014-
1015-
if axis is ax.get_xaxis():
1016-
xmin, xmax = ax.dataLim.intervalx
1017-
if xmin==0.:
1018-
# no data has been added - let's set the default datalim.
1019-
# We should probably use a better proxy for the datalim
1020-
# have been updated than the ignore setting
1021-
dmax = today = datetime.date.today()
1022-
dmin = today-datetime.timedelta(days=10)
1023-
1024-
ax._process_unit_info(xdata=(dmin, dmax))
1025-
dmin, dmax = ax.convert_xunits([dmin, dmax])
1026-
1027-
ax.viewLim.intervalx = dmin, dmax
1028-
ax.dataLim.intervalx = dmin, dmax
1029-
elif axis is ax.get_yaxis():
1030-
ymin, ymax = ax.dataLim.intervaly
1031-
if ymin==0.:
1032-
# no data has been added - let's set the default datalim.
1033-
# We should probably use a better proxy for the datalim
1034-
# have been updated than the ignore setting
1035-
dmax = today = datetime.date.today()
1036-
dmin = today-datetime.timedelta(days=10)
1037-
1038-
ax._process_unit_info(ydata=(dmin, dmax))
1039-
dmin, dmax = ax.convert_yunits([dmin, dmax])
1040-
1041-
ax.viewLim.intervaly = dmin, dmax
1042-
ax.dataLim.intervaly = dmin, dmax
1013+
if axis:
1014+
ax = axis.axes
1015+
1016+
if axis is ax.get_xaxis():
1017+
xmin, xmax = ax.dataLim.intervalx
1018+
if xmin==0.:
1019+
# no data has been added - let's set the default datalim.
1020+
# We should probably use a better proxy for the datalim
1021+
# have been updated than the ignore setting
1022+
dmax = today = datetime.date.today()
1023+
dmin = today-datetime.timedelta(days=10)
1024+
1025+
ax._process_unit_info(xdata=(dmin, dmax))
1026+
dmin, dmax = ax.convert_xunits([dmin, dmax])
1027+
1028+
ax.viewLim.intervalx = dmin, dmax
1029+
ax.dataLim.intervalx = dmin, dmax
1030+
elif axis is ax.get_yaxis():
1031+
ymin, ymax = ax.dataLim.intervaly
1032+
if ymin==0.:
1033+
# no data has been added - let's set the default datalim.
1034+
# We should probably use a better proxy for the datalim
1035+
# have been updated than the ignore setting
1036+
dmax = today = datetime.date.today()
1037+
dmin = today-datetime.timedelta(days=10)
1038+
1039+
ax._process_unit_info(ydata=(dmin, dmax))
1040+
dmin, dmax = ax.convert_yunits([dmin, dmax])
1041+
1042+
ax.viewLim.intervaly = dmin, dmax
1043+
ax.dataLim.intervaly = dmin, dmax
10431044

10441045
majloc = AutoDateLocator(tz=unit)
10451046
majfmt = AutoDateFormatter(majloc, tz=unit)
10461047
return units.AxisInfo( majloc=majloc, majfmt=majfmt, label='' )
10471048

10481049
@staticmethod
1049-
def convert(axis, value, unit):
1050+
def convert(value, unit, axis):
10501051
if units.ConversionInterface.is_numlike(value): return value
10511052
return date2num(value)
10521053

10531054
@staticmethod
1054-
def default_units(axis, x):
1055+
def default_units(x, axis):
10551056
'Return the default unit for *x* or None'
10561057
return None
10571058

lib/matplotlib/units.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,17 @@ class ConversionInterface:
6969
sequences) and convert them to values mpl can use
7070
"""
7171
@staticmethod
72-
def axisinfo(axis, unit):
72+
def axisinfo(unit, axis):
7373
'return an units.AxisInfo instance for axis with the specified units'
7474
return None
7575

7676
@staticmethod
77-
def default_units(axis, x):
77+
def default_units(x, axis):
7878
'return the default unit for x or None for the given axis'
7979
return None
8080

8181
@staticmethod
82-
def convert(axis, obj, unit):
82+
def convert(obj, unit, axis):
8383
"""
8484
convert obj using unit for the specified axis. If obj is a sequence,
8585
return the converted sequence. The ouput must be a sequence of scalars

0 commit comments

Comments
 (0)