Skip to content

Commit 800ef38

Browse files
committed
Minor corrections to documentation
1 parent 8143153 commit 800ef38

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

examples/scales/asinh_demo.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020
2121
.. math::
2222
23-
a \\rightarrow a_0 \\ln (a) + {\\cal O}(1)
23+
a \\rightarrow a_0 \\, {\\rm sgn}(a) \\ln |a| + {\\cal O}(1)
2424
2525
As with the `symlog` scaling, this allows one to plot quantities
2626
that cover a very wide dynamic range that includes both positive
2727
and negative values. However, `symlog` involves a tranformation
2828
that has discontinuities in its gradient because it is built
29-
from *separate* linear and logarithmic transformation.
29+
from *separate* linear and logarithmic transformations.
3030
The `asinh` scaling uses a transformation that is smooth
3131
for all (finite) values, which is both mathematically cleaner
3232
and should reduce visual artifacts associated with an abrupt
@@ -35,14 +35,15 @@
3535
See `~.scale.AsinhScale`, `~.scale.SymmetricalLogScale`.
3636
"""
3737

38-
import numpy
38+
import numpy as np
3939
import matplotlib.pyplot as plt
4040

4141
# Prepare sample values for variations on y=x graph:
42-
x = numpy.linspace(-3, 6, 100)
42+
x = np.linspace(-3, 6, 100)
4343

4444
########################################
45-
# Compare "symlog" and "asinh" behaviour on sample y=x graph:
45+
# Compare "symlog" and "asinh" behaviour on sample y=x graph,
46+
# where the discontinuous gradient in "symlog" near y=2 is obvious:
4647
fig1 = plt.figure()
4748
ax0, ax1 = fig1.subplots(1, 2, sharex=True)
4849

@@ -73,19 +74,23 @@
7374

7475
########################################
7576
# Compare "symlog" and "asinh" scalings
76-
# on 2D Cauchy-distributed random numbers:
77+
# on 2D Cauchy-distributed random numbers,
78+
# where one may be able to see more subtle artifacts near y=2
79+
# due to the gradient-discontinuity in "symlog":
7780
fig3 = plt.figure()
7881
ax = fig3.subplots(1, 1)
79-
r = numpy.tan(numpy.random.uniform(-numpy.pi / 2.02, numpy.pi / 2.02,
80-
size=(5000,)))
81-
th = numpy.random.uniform(0, 2*numpy.pi, size=r.shape)
82+
r = 3 * np.tan(np.random.uniform(-np.pi / 2.01, np.pi / 2.01,
83+
size=(5000,)))
84+
th = np.random.uniform(0, 2*np.pi, size=r.shape)
8285

83-
ax.scatter(r * numpy.cos(th), r * numpy.sin(th), s=4, alpha=0.5)
86+
ax.scatter(r * np.cos(th), r * np.sin(th), s=4, alpha=0.5)
8487
ax.set_xscale('asinh')
8588
ax.set_yscale('symlog')
8689
ax.set_xlabel('asinh')
8790
ax.set_ylabel('symlog')
8891
ax.set_title('2D Cauchy random deviates')
92+
ax.set_xlim(-50, 50)
93+
ax.set_ylim(-50, 50)
8994
ax.grid()
9095

9196

lib/matplotlib/scale.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,7 @@ def get_transform(self):
459459

460460

461461
class AsinhTransform(Transform):
462+
"""Inverse hyperbolic-sine transformation used by `.AsinhScale`"""
462463
input_dims = output_dims = 1
463464

464465
def __init__(self, linear_width):
@@ -473,6 +474,7 @@ def inverted(self):
473474

474475

475476
class InvertedAsinhTransform(Transform):
477+
"""Hyperbolic-sine transformation used by `.AsinhScale`"""
476478
input_dims = output_dims = 1
477479

478480
def __init__(self, linear_width):
@@ -493,16 +495,16 @@ class AsinhScale(ScaleBase):
493495
For values close to zero, this is essentially a linear scale,
494496
but for larger values (either positive or negative) it is asymptotically
495497
logarithmic. The transition between these linear and logarithmic regimes
496-
is smooth, and has no discontinutities in the function gradient
497-
in contrast to the "symlog" scale.
498+
is smooth, and has no discontinuities in the function gradient
499+
in contrast to the `symlog` scale.
498500
499501
Specifically, the transformation of an axis coordinate :math:`a` is
500-
is :math:`a \\rightarrow a_0 \\sinh^{-1} (a / a_0)` where :math:`a_0`
502+
:math:`a \\rightarrow a_0 \\sinh^{-1} (a / a_0)` where :math:`a_0`
501503
is the effective width of the linear region of the transformation.
502504
In that region, the transformation is
503505
:math:`a \\rightarrow a + {\\cal O}(a^3)`.
504506
For large values of :math:`a` the transformation behaves as
505-
:math:`a \\rightarrow a_0 \\ln (a) + {\\cal O}(1)`.
507+
:math:`a \\rightarrow a_0 \\, {\\rm sgn}(a) \\ln |a| + {\\cal O}(1)`.
506508
"""
507509

508510
name = 'asinh'
@@ -515,7 +517,7 @@ def __init__(self, axis, *, linear_width=1.0, **kwargs):
515517
The scale parameter (elsewhere referred to as :math:`a_0`)
516518
defining the extent of the quasi-linear region,
517519
and the coordinate values beyond which the transformation
518-
becomes asympoticially logarithmic.
520+
becomes asympotically logarithmic.
519521
"""
520522
super().__init__(axis)
521523
if linear_width <= 0.0:

0 commit comments

Comments
 (0)