|
2 | 2 | Tick locating and formatting |
3 | 3 | ============================ |
4 | 4 |
|
5 | | -This module contains classes to support completely configurable tick |
6 | | -locating and formatting. Although the locators know nothing about major |
7 | | -or minor ticks, they are used by the Axis class to support major and |
8 | | -minor tick locating and formatting. Generic tick locators and |
9 | | -formatters are provided, as well as domain specific custom ones. |
| 5 | +This module contains classes for configuring tick locating and formatting. |
| 6 | +Generic tick locators and formatters are provided, as well as domain specific |
| 7 | +custom ones. |
10 | 8 |
|
11 | | -Default Formatter |
12 | | ------------------ |
13 | | -
|
14 | | -The default formatter identifies when the x-data being plotted is a |
15 | | -small range on top of a large offset. To reduce the chances that the |
16 | | -ticklabels overlap, the ticks are labeled as deltas from a fixed offset. |
17 | | -For example:: |
18 | | -
|
19 | | - ax.plot(np.arange(2000, 2010), range(10)) |
20 | | -
|
21 | | -will have tick of 0-9 with an offset of +2e3. If this is not desired |
22 | | -turn off the use of the offset on the default formatter:: |
23 | | -
|
24 | | - ax.get_xaxis().get_major_formatter().set_useOffset(False) |
25 | | -
|
26 | | -Set :rc:`axes.formatter.useoffset` to turn it off |
27 | | -globally, or set a different formatter. |
| 9 | +Although the locators know nothing about major or minor ticks, they are used |
| 10 | +by the Axis class to support major and minor tick locating and formatting. |
28 | 11 |
|
29 | 12 | Tick locating |
30 | 13 | ------------- |
|
142 | 125 | Probability formatter. |
143 | 126 |
|
144 | 127 | :class:`EngFormatter` |
145 | | - Format labels in engineering notation |
| 128 | + Format labels in engineering notation. |
146 | 129 |
|
147 | 130 | :class:`PercentFormatter` |
148 | | - Format labels as a percentage |
| 131 | + Format labels as a percentage. |
149 | 132 |
|
150 | 133 | You can derive your own formatter from the Formatter base class by |
151 | 134 | simply overriding the ``__call__`` method. The formatter class has |
@@ -501,13 +484,38 @@ class ScalarFormatter(Formatter): |
501 | 484 | In addition to the parameters above, the formatting of scientific vs. |
502 | 485 | floating point representation can be configured via `.set_scientific` |
503 | 486 | and `.set_powerlimits`). |
| 487 | +
|
| 488 | + **Offset notation and scientific notation** |
| 489 | +
|
| 490 | + Offset notation and scientific notation look quite similar at first sight. |
| 491 | + Both split some information from the formatted tick values and display it |
| 492 | + at the end of the axis. |
| 493 | +
|
| 494 | + - The scientific notation splits up the order of magnitude, i.e. a |
| 495 | + multiplicative scaling factor, e.g. ``1e6``. |
| 496 | +
|
| 497 | + - The offset notation separates an additive constant, e.g. ``+1e6``. The |
| 498 | + offset notation label is always prefixed with a ``+`` or ``-`` sign |
| 499 | + and is thus distinguishable from the order of magnitude label. |
| 500 | +
|
| 501 | + The following plot with x limits ``1_000_000`` to ``1_000_010`` illustrates |
| 502 | + the different formatting. Note the labels at the right edge of the x axis. |
| 503 | +
|
| 504 | + .. plot:: |
| 505 | +
|
| 506 | + lim = (1_000_000, 1_000_010) |
| 507 | +
|
| 508 | + fig, (ax1, ax2, ax3) = plt.subplots(3, 1, gridspec_kw={'hspace': 2}) |
| 509 | + ax1.set(title='offset_notation', xlim=lim) |
| 510 | + ax2.set(title='scientific notation', xlim=lim) |
| 511 | + ax2.xaxis.get_major_formatter().set_useOffset(False) |
| 512 | + ax3.set(title='floating point notation', xlim=lim) |
| 513 | + ax3.xaxis.get_major_formatter().set_useOffset(False) |
| 514 | + ax3.xaxis.get_major_formatter().set_scientific(False) |
| 515 | +
|
504 | 516 | """ |
505 | 517 |
|
506 | 518 | def __init__(self, useOffset=None, useMathText=None, useLocale=None): |
507 | | - # useOffset allows plotting small data ranges with large offsets: for |
508 | | - # example: [1+1e-9, 1+2e-9, 1+3e-9] useMathText will render the offset |
509 | | - # and scientific notation in mathtext |
510 | | - |
511 | 519 | if useOffset is None: |
512 | 520 | useOffset = mpl.rcParams['axes.formatter.useoffset'] |
513 | 521 | self._offset_threshold = \ |
|
0 commit comments