Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 76d9b42

Browse files
committed
Improved overview documentation
1 parent 279c38b commit 76d9b42

File tree

4 files changed

+68
-7
lines changed

4 files changed

+68
-7
lines changed

doc/users/next_whats_new/asinh_scale.rst

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,29 @@ The new ``asinh`` axis scale offers an alternative to ``symlog`` that
55
smoothly transitions between the quasi-linear and asymptotically logarithmic
66
regions of the scale. This is based on an arcsinh transformation that
77
allows plotting both positive and negative values than span many orders
8-
of magnitude. A scale parameter ``a0`` is provided to allow the user
8+
of magnitude. A scale parameter is provided to allow the user
99
to tune the width of the linear region of the scale.
10+
11+
.. plot::
12+
13+
from matplotlib import pyplot as plt
14+
import numpy
15+
16+
fig, (ax0, ax1) = plt.subplots(1, 2, sharex=True)
17+
x = numpy.linspace(-3, 6, 100)
18+
19+
ax0.plot(x, x)
20+
ax0.set_yscale('symlog')
21+
ax0.grid()
22+
ax0.set_title('symlog')
23+
24+
ax1.plot(x, x)
25+
ax1.set_yscale('asinh')
26+
ax1.grid()
27+
ax1.set_title(r'$sinh^{-1}$')
28+
29+
for p in (-2, 2):
30+
for ax in (ax0, ax1):
31+
c = plt.Circle((p, p), radius=0.5, fill=False,
32+
color='red', alpha=0.8, lw=3)
33+
ax.add_patch(c)

examples/scales/asinh_demo.py

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,37 @@
22
============
33
Asinh Demo
44
============
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`.
536
"""
637

738
import numpy
@@ -10,6 +41,7 @@
1041
# Prepare sample values for variations on y=x graph:
1142
x = numpy.linspace(-3, 6, 100)
1243

44+
########################################
1345
# Compare "symlog" and "asinh" behaviour on sample y=x graph:
1446
fig1 = plt.figure()
1547
ax0, ax1 = fig1.subplots(1, 2, sharex=True)
@@ -22,12 +54,13 @@
2254
ax1.plot(x, x)
2355
ax1.set_yscale('asinh')
2456
ax1.grid()
25-
ax1.set_title(r'$sinh^{-1}$')
57+
ax1.set_title('asinh')
2658

2759

60+
########################################
2861
# Compare "asinh" graphs with different scale parameter "linear_width":
2962
fig2 = plt.figure()
30-
axs = fig2.subplots(1, 3, sharex=True)
63+
axs = fig2.subplots(1, 3, sharex=True, constrained_layout=True)
3164
for ax, a0 in zip(axs, (0.2, 1.0, 5.0)):
3265
ax.set_title('linear_width={:.3g}'.format(a0))
3366
ax.plot(x, x, label='y=x')
@@ -38,6 +71,7 @@
3871
ax.legend(loc='best', fontsize='small')
3972

4073

74+
########################################
4175
# Compare "symlog" and "asinh" scalings
4276
# on 2D Cauchy-distributed random numbers:
4377
fig3 = plt.figure()

lib/matplotlib/scale.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -497,12 +497,12 @@ class AsinhScale(ScaleBase):
497497
in contrast to the "symlog" scale.
498498
499499
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`
500+
is :math:`a \\rightarrow a_0 \\sinh^{-1} (a / a_0)` where :math:`a_0`
501501
is the effective width of the linear region of the transformation.
502502
In that region, the transformation is
503-
:math:`a \\rightarrow a + {\cal O}(a^3)`.
503+
:math:`a \\rightarrow a + {\\cal O}(a^3)`.
504504
For large values of :math:`a` the transformation behaves as
505-
:math:`a \\rightarrow a_0 \ln (a) + {\cal O}(1)`.
505+
:math:`a \\rightarrow a_0 \\ln (a) + {\\cal O}(1)`.
506506
"""
507507

508508
name = 'asinh'

lib/matplotlib/ticker.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2640,7 +2640,10 @@ def tick_values(self, vmin, vmax):
26402640
)
26412641
qs = decades * np.round(xs / decades)
26422642

2643-
return np.array(sorted(set(qs)))
2643+
if len(qs) > self.numticks // 2:
2644+
return np.array(sorted(set(qs)))
2645+
else:
2646+
return np.linspace(vmin, vmax, self.numticks)
26442647

26452648

26462649
class LogitLocator(MaxNLocator):

0 commit comments

Comments
 (0)