~ubuntu-branches/ubuntu/precise/pyx/precise

« back to all changes in this revision

Viewing changes to manual/unit.rst

  • Committer: Bazaar Package Importer
  • Author(s): Stuart Prescott
  • Date: 2011-05-20 00:13:52 UTC
  • mfrom: (2.1.6 sid)
  • Revision ID: james.westby@ubuntu.com-20110520001352-0textf3thrb8qim6
Tags: 0.11.1-1
* New upstream release.
* Change documentation build system to sphinx in line with new upstream docs.
* Rebuild lfs files as part of build process.
* Refresh patchs for new version:
  - drop manual-latex-define.patch no longer needed with sphinx.
  - drop siteconfig-static.patch: not needed with new build system
  - drop pyx-text-warnings26.patch: warnings fixed upstream
* Add patch sphinx-mathjax.patch to use pngmath in sphinx rather than mathjax
  which is not yet in Debian.
* Add patch createlfs-no-foiltex.patch to skip generation of foiltex-based
  lfs files that would require non-free components.
* Switch to dpkg-source 3.0 (quilt) format.
* Switch from python-support to dh_python2 as build helper.
* Update copyright format to newer DEP-5 specification.
* Add new files to copyright file.
* Bump standards version to 3.9.2 (no changes required).
* Set DM-Upload-Allowed: yes

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
.. module:: unit
 
3
 
 
4
******************
 
5
Module :mod:`unit`
 
6
******************
 
7
 
 
8
.. sectionauthor:: Jörg Lehmann <joergl@users.sourceforge.net>
 
9
 
 
10
 
 
11
 
 
12
 
 
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:
 
22
 
 
23
user length:
 
24
   used for lengths of graphical objects like positions etc.
 
25
 
 
26
visual length:
 
27
   used for sizes of visual elements, like arrows, graph symbols, axis ticks, etc.
 
28
 
 
29
width length:
 
30
   used for line widths
 
31
 
 
32
TeX length:
 
33
   used for all TeX and LaTeX output
 
34
 
 
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
 
38
 
 
39
 
 
40
.. function:: set(uscale=None, vscale=None, wscale=None, xscale=None, defaultunit=None)
 
41
 
 
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"``.
 
46
 
 
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  ::
 
49
 
 
50
   unit.set(wscale=2)
 
51
 
 
52
Or suppose, you are used to specify length in imperial units. In this,
 
53
admittedly rather unfortunate case, just use  ::
 
54
 
 
55
   unit.set(defaultunit="inch")
 
56
 
 
57
at the beginning of your program.
 
58
 
 
59
 
 
60
Class length
 
61
============
 
62
 
 
63
 
 
64
.. class:: length(f, type="u", unit=None)
 
65
 
 
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
 
74
   ``"pt"``.
 
75
 
 
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.
 
83
 
 
84
 
 
85
Predefined length instances
 
86
===========================
 
87
 
 
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
 
90
table
 
91
 
 
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
+-----------------+--------+--------+
 
155
 
 
156
Thus, in order to specify, e.g., a length of 5 width points, just use
 
157
``5*unit.w_pt``.
 
158
 
 
159
 
 
160
Conversion functions
 
161
====================
 
162
 
 
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
 
165
 
 
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
+---------------+--------------------------+
 
179
 
 
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.
 
182