← 返回首页
Colorization · rai-opensource/spatialmath-python Wiki · GitHub
Skip to content

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus

Colorization

Peter Corke edited this page Aug 9, 2020 · 1 revision

Colorized output

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.

Disabling colorized output

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

Wiki pages Pages 11

Clone this wiki locally

Footer

© 2026 GitHub, Inc.