units
class
Foo
:
def
__init__
(
self
,
val
,
unit
=
1.0
):
self
.
unit
=
unit
self
.
_val
=
val
*
unit
def
value
(
self
,
unit
):
if
unit
is
None
:
unit
=
self
.
unit
return
self
.
_val
/
unit
class
FooConverter
(
):
@staticmethod
def
axisinfo
(
unit
,
axis
):
"""Return the Foo AxisInfo."""
if
unit
==
1.0
or
unit
==
2.0
:
return
(
majloc
=
(
8
,
0
),
majfmt
=
(
"VAL:
%s
"
),
label
=
'foo'
,
)
else
:
return
None
@staticmethod
def
convert
(
obj
,
unit
,
axis
):
"""
Convert *obj* using *unit*.
If *obj* is a sequence, return the converted sequence.
"""
if
(
obj
):
return
[
o
.
value
(
unit
)
for
o
in
obj
]
else
:
return
obj
.
value
(
unit
)
@staticmethod
def
default_units
(
,
axis
):
"""Return the default unit for *x* or None."""
if
(
):
for
thisx
in
:
return
thisx
.
unit
else
:
return
[
Foo
]
=
()
=
[
Foo
(
val
,
1.0
)
for
val
in
range
(
0
,
50
,
2
)]
=
[
i
for
i
in
range
(
len
(
))]
,
(
,
)
=
(
1
,
2
)
(
"Custom units"
)
(
bottom
=
0.2
)
(
,
,
'o'
,
xunits
=
2.0
)
(
"xunits = 2.0"
)
(
axis
=
'x'
,
rotation
=
30
,
rotation_mode
=
'xtick'
)
(
,
)
(
'default units'
)
(
axis
=
'x'
,
rotation
=
30
,
rotation_mode
=
'xtick'
)
()