-
Notifications
You must be signed in to change notification settings - Fork 85
Colorization
Peter Corke edited this page Aug 9, 2020
·
1 revision
If the package coloured
is found it will be loaded when you import spatial math.
>>> import spatialmath as sm
>>> a = sm.SE3()
>>> a
SE3(array([[1., 0., 0., 0.],
[0., 1., 0., 0.],
[0., 0., 1., 0.],
[0., 0., 0., 1.]]))
>>> print(a)
where the matrix has a light-grey background and the elements are color coded:
- red for rotation matrix
- blue for translation (SE(n) only)
- grey for constant values
This colorisation is achieved by ANSI escape sequences which can be seen in the stringed version of the pose
>>> str(a)
' \x1b[38;5;1m\x1b[48;5;255m 1 \x1b[0m\x1b[38;5;1m\x1b[48;5;255m 0 \x1b[0m\x1b[38;5;1m\x1b[48;5;255m 0 \x1b[0m\x1b[38;5;4m\x1b[48;5;255m 0 \x1b[0m\x1b[48;5;255m \x1b[0m\n \x1b[38;5;1m\x1b[48;5;255m 0 \x1b[0m\x1b[38;5;1m\x1b[48;5;255m 1 \x1b[0m\x1b[38;5;1m\x1b[48;5;255m 0 \x1b[0m\x1b[38;5;4m\x1b[48;5;255m 0 \x1b[0m\x1b[48;5;255m \x1b[0m\n \x1b[38;5;1m\x1b[48;5;255m 0 \x1b[0m\x1b[38;5;1m\x1b[48;5;255m 0 \x1b[0m\x1b[38;5;1m\x1b[48;5;255m 1 \x1b[0m\x1b[38;5;4m\x1b[48;5;255m 0 \x1b[0m\x1b[48;5;255m \x1b[0m\n \x1b[38;5;244m\x1b[48;5;255m 0 \x1b[0m\x1b[38;5;244m\x1b[48;5;255m 0 \x1b[0m\x1b[38;5;244m\x1b[48;5;255m 0 \x1b[0m\x1b[38;5;244m\x1b[48;5;255m 1 \x1b[0m\x1b[48;5;255m \x1b[0m\n'
which looks ugly, but if you pass the string to print
(and are using a console that supports color, most do) it will do the right thing and you will see color and not ugly escape sequences.
In addition to any other imports of spatialmath
do the following
>>> import spatialmath.super_pose as sp
>>> sp._color=False
>>> print(a)
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1