|
2 | 2 | ============ |
3 | 3 | Asinh Demo |
4 | 4 | ============ |
| 5 | +
|
| 6 | +Illustration of the `asinh` axis scaling, which uses the transformation |
| 7 | +
|
| 8 | +.. math:: |
| 9 | +
|
| 10 | + a \\rightarrow a_0 \\sinh^{-1} (a / a_0) |
| 11 | +
|
| 12 | +For coordinate values close to zero (i.e. much smaller than |
| 13 | +the "linear width" :math:`a_0`), this leaves values essentially unchanged: |
| 14 | +
|
| 15 | +.. math:: |
| 16 | +
|
| 17 | + a \\rightarrow a + {\\cal O}(a^3) |
| 18 | +
|
| 19 | +but for larger values (i.e. :math:`|a| \gg a_0`, this is asymptotically |
| 20 | +
|
| 21 | +.. math:: |
| 22 | +
|
| 23 | + a \\rightarrow a_0 \\ln (a) + {\\cal O}(1) |
| 24 | +
|
| 25 | +As with the `symlog` scaling, this allows one to plot quantities |
| 26 | +that cover a very wide dynamic range that includes both positive |
| 27 | +and negative values. However, `symlog` involves a tranformation |
| 28 | +that has discontinuities in its gradient because it is built |
| 29 | +from *separate* linear and logarithmic transformation. |
| 30 | +The `asinh` scaling uses a transformation that is smooth |
| 31 | +for all (finite) values, which is both mathematically cleaner |
| 32 | +and should reduce visual artifacts associated with an abrupt |
| 33 | +transition between linear and logarithmic regions of the plot. |
| 34 | +
|
| 35 | +See `~.scale.AsinhScale`, `~.scale.SymmetricalLogScale`. |
5 | 36 | """ |
6 | 37 |
|
7 | 38 | import numpy |
|
10 | 41 | # Prepare sample values for variations on y=x graph: |
11 | 42 | x = numpy.linspace(-3, 6, 100) |
12 | 43 |
|
| 44 | +######################################## |
13 | 45 | # Compare "symlog" and "asinh" behaviour on sample y=x graph: |
14 | 46 | fig1 = plt.figure() |
15 | 47 | ax0, ax1 = fig1.subplots(1, 2, sharex=True) |
|
22 | 54 | ax1.plot(x, x) |
23 | 55 | ax1.set_yscale('asinh') |
24 | 56 | ax1.grid() |
25 | | -ax1.set_title(r'$sinh^{-1}$') |
| 57 | +ax1.set_title('asinh') |
26 | 58 |
|
27 | 59 |
|
| 60 | +######################################## |
28 | 61 | # Compare "asinh" graphs with different scale parameter "linear_width": |
29 | 62 | fig2 = plt.figure() |
30 | | -axs = fig2.subplots(1, 3, sharex=True) |
| 63 | +axs = fig2.subplots(1, 3, sharex=True, constrained_layout=True) |
31 | 64 | for ax, a0 in zip(axs, (0.2, 1.0, 5.0)): |
32 | 65 | ax.set_title('linear_width={:.3g}'.format(a0)) |
33 | 66 | ax.plot(x, x, label='y=x') |
|
38 | 71 | ax.legend(loc='best', fontsize='small') |
39 | 72 |
|
40 | 73 |
|
| 74 | +######################################## |
41 | 75 | # Compare "symlog" and "asinh" scalings |
42 | 76 | # on 2D Cauchy-distributed random numbers: |
43 | 77 | fig3 = plt.figure() |
|
0 commit comments