8
.. sectionauthor:: Jörg Lehmann <joergl@users.sourceforge.net>
13
With the ``unit`` module PyX makes available classes and functions for the
14
specification and manipulation of lengths. As usual, lengths consist of a number
15
together with a measurement unit, e.g., 1 cm, 50 points, 0.42 inch. In
16
addition, lengths in PyX are composed of the five types "true", "user",
17
"visual", "width", and "TeX", e.g., 1 user cm, 50 true points, 0.42 visual + 0.2
18
width inch. As their names indicate, they serve different purposes. True
19
lengths are not scalable and are mainly used for return values of PyX functions.
20
The other length types can be rescaled by the user and differ with respect to
21
the type of object they are applied to:
24
used for lengths of graphical objects like positions etc.
27
used for sizes of visual elements, like arrows, graph symbols, axis ticks, etc.
33
used for all TeX and LaTeX output
35
When not specified otherwise, all types of lengths are interpreted in terms of a
36
default unit, which, by default, is 1 cm. You may change this default unit by
37
using the module level function
40
.. function:: set(uscale=None, vscale=None, wscale=None, xscale=None, defaultunit=None)
42
When *uscale*, *vscale*, *wscale*, or *xscale* is not `None`, the
43
corresponding scaling factor(s) is redefined to the given number. When
44
*defaultunit* is not `None`, the default unit is set to the given
45
value, which has to be one of ``"cm"``, ``"mm"``, ``"inch"``, or ``"pt"``.
47
For instance, if you only want thicker lines for a publication version of your
48
figure, you can just rescale all width lengths using ::
52
Or suppose, you are used to specify length in imperial units. In this,
53
admittedly rather unfortunate case, just use ::
55
unit.set(defaultunit="inch")
57
at the beginning of your program.
64
.. class:: length(f, type="u", unit=None)
66
The constructor of the :class:`length` class expects as its first argument a
67
number *f*, which represents the prefactor of the given length. By default this
68
length is interpreted as a user length (``type="u"``) in units of the current
69
default unit (see :func:`set` function of the :mod:`unit` module). Optionally, a
70
different *type* may be specified, namely ``"u"`` for user lengths, ``"v"`` for
71
visual lengths, ``"w"`` for width lengths, ``"x"`` for TeX length, and ``"t"``
72
for true lengths. Furthermore, a different unit may be specified using the
73
*unit* argument. Allowed values are ``"cm"``, ``"mm"``, ``"inch"``, and
76
Instances of the :class:`length` class support addition and substraction either
77
by another :class:`length` or by a number which is then interpeted as being a
78
user length in default units, multiplication by a number and division either by
79
another :class:`length` in which case a float is returned or by a number in
80
which case a :class:`length` instance is returned. When two lengths are
81
compared, they are first converted to meters (using the currently set scaling),
82
and then the resulting values are compared.
85
Predefined length instances
86
===========================
88
A number of ``length`` instances are already predefined, which only differ in
89
there values for ``type`` and ``unit``. They are summarized in the following
92
+-----------------+--------+--------+
93
| name | type | unit |
94
+=================+========+========+
95
| :const:`m` | user | m |
96
+-----------------+--------+--------+
97
| :const:`cm` | user | cm |
98
+-----------------+--------+--------+
99
| :const:`mm` | user | mm |
100
+-----------------+--------+--------+
101
| :const:`inch` | user | inch |
102
+-----------------+--------+--------+
103
| :const:`pt` | user | points |
104
+-----------------+--------+--------+
105
| :const:`t_m` | true | m |
106
+-----------------+--------+--------+
107
| :const:`t_cm` | true | cm |
108
+-----------------+--------+--------+
109
| :const:`t_mm` | true | mm |
110
+-----------------+--------+--------+
111
| :const:`t_inch` | true | inch |
112
+-----------------+--------+--------+
113
| :const:`t_pt` | true | points |
114
+-----------------+--------+--------+
115
| :const:`u_m` | user | m |
116
+-----------------+--------+--------+
117
| :const:`u_cm` | user | cm |
118
+-----------------+--------+--------+
119
| :const:`u_mm` | user | mm |
120
+-----------------+--------+--------+
121
| :const:`u_inch` | user | inch |
122
+-----------------+--------+--------+
123
| :const:`u_pt` | user | points |
124
+-----------------+--------+--------+
125
| :const:`v_m` | visual | m |
126
+-----------------+--------+--------+
127
| :const:`v_cm` | visual | cm |
128
+-----------------+--------+--------+
129
| :const:`v_mm` | visual | mm |
130
+-----------------+--------+--------+
131
| :const:`v_inch` | visual | inch |
132
+-----------------+--------+--------+
133
| :const:`v_pt` | visual | points |
134
+-----------------+--------+--------+
135
| :const:`w_m` | width | m |
136
+-----------------+--------+--------+
137
| :const:`w_cm` | width | cm |
138
+-----------------+--------+--------+
139
| :const:`w_mm` | width | mm |
140
+-----------------+--------+--------+
141
| :const:`w_inch` | width | inch |
142
+-----------------+--------+--------+
143
| :const:`w_pt` | width | points |
144
+-----------------+--------+--------+
145
| :const:`x_m` | TeX | m |
146
+-----------------+--------+--------+
147
| :const:`x_cm` | TeX | cm |
148
+-----------------+--------+--------+
149
| :const:`x_mm` | TeX | mm |
150
+-----------------+--------+--------+
151
| :const:`x_inch` | TeX | inch |
152
+-----------------+--------+--------+
153
| :const:`x_pt` | TeX | points |
154
+-----------------+--------+--------+
156
Thus, in order to specify, e.g., a length of 5 width points, just use
163
If you want to know the value of a PyX length in certain units, you may use the
164
predefined conversion functions which are given in the following table
166
+---------------+--------------------------+
167
| function | result |
168
+===============+==========================+
169
| ``tom(l)`` | ``l`` in units of m |
170
+---------------+--------------------------+
171
| ``tocm(l)`` | ``l`` in units of cm |
172
+---------------+--------------------------+
173
| ``tomm(l)`` | ``l`` in units of mm |
174
+---------------+--------------------------+
175
| ``toinch(l)`` | ``l`` in units of inch |
176
+---------------+--------------------------+
177
| ``topt(l)`` | ``l`` in units of points |
178
+---------------+--------------------------+
180
If ``l`` is not yet a ``length`` instance but a number, it first is interpreted
181
as a user length in the default units.