Skip to content

Commit 7bec3f4

Browse files
committed
Patched tick-generation on pan/zoom & misc. tidying
1 parent 3d92406 commit 7bec3f4

File tree

6 files changed

+19
-17
lines changed

6 files changed

+19
-17
lines changed

doc/users/next_whats_new/asinh_scale.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ 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 that span many orders
8-
of magnitude. A scale parameter is provided to allow the user
9-
to tune the width of the linear region of the scale.
8+
of magnitude.
109

1110
.. plot::
1211

examples/images_contours_and_fields/colormap_normalizations_symlognorm.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def rbf(x, y):
3535

3636
shadeopts = {'cmap': 'PRGn', 'shading': 'gouraud'}
3737
colormap = 'PRGn'
38-
lnrwidth = 0.2
38+
lnrwidth = 0.5
3939

4040
fig, ax = plt.subplots(2, 1, sharex=True, sharey=True)
4141

@@ -60,23 +60,23 @@ def rbf(x, y):
6060
# the option of using the `~.colors.AsinhNorm`, which has a smoother
6161
# transition between the linear and logarithmic regions of the transformation
6262
# applied to the "z" axis.
63-
# In the plots below, it may be possible to see ring-like artifacts
64-
# in the lower-amplitude, negative, hump shown in purple despite
65-
# there being no sharp features in the dataset itself.
66-
# The ``asinh`` scaling shows a smoother shading of each hump.
63+
# In the plots below, it may be possible to see contour-like artifacts
64+
# around each hump despite there being no sharp features
65+
# in the dataset itself. The ``asinh`` scaling shows a smoother shading
66+
# of each hump.
6767

6868
fig, ax = plt.subplots(2, 1, sharex=True, sharey=True)
6969

7070
pcm = ax[0].pcolormesh(X, Y, Z,
7171
norm=colors.SymLogNorm(linthresh=lnrwidth, linscale=1,
72-
vmin=-2, vmax=gain, base=10),
72+
vmin=-gain, vmax=gain, base=10),
7373
**shadeopts)
7474
fig.colorbar(pcm, ax=ax[0], extend='both')
7575
ax[0].text(-2.5, 1.5, 'symlog')
7676

7777
pcm = ax[1].pcolormesh(X, Y, Z,
7878
norm=colors.AsinhNorm(linear_width=lnrwidth,
79-
vmin=-2, vmax=gain),
79+
vmin=-gain, vmax=gain),
8080
**shadeopts)
8181
fig.colorbar(pcm, ax=ax[1], extend='both')
8282
ax[1].text(-2.5, 1.5, 'asinh')

examples/scales/asinh_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
# Compare "asinh" graphs with different scale parameter "linear_width":
6565
fig2 = plt.figure(constrained_layout=True)
6666
axs = fig2.subplots(1, 3, sharex=True)
67-
for ax, (a0, base) in zip(axs, ((0.2, 2), (1.0, 0), (5.0, 3))):
67+
for ax, (a0, base) in zip(axs, ((0.2, 2), (1.0, 0), (5.0, 10))):
6868
ax.set_title('linear_width={:.3g}'.format(a0))
6969
ax.plot(x, x, label='y=x')
7070
ax.plot(x, 10*x, label='y=10x')

lib/matplotlib/scale.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,8 @@ class AsinhTransform(Transform):
465465
def __init__(self, linear_width):
466466
super().__init__()
467467
if linear_width <= 0.0:
468-
raise ValueError("Scale parameter 'linear_width' must be strictly positive")
468+
raise ValueError("Scale parameter 'linear_width' " +
469+
"must be strictly positive")
469470
self.linear_width = linear_width
470471

471472
def transform_non_affine(self, a):

lib/matplotlib/tests/test_ticker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ def test_symmetrizing(self):
517517
class DummyAxis:
518518
bounds = (-1, 1)
519519
@classmethod
520-
def get_data_interval(cls): return cls.bounds
520+
def get_view_interval(cls): return cls.bounds
521521

522522
lctr = mticker.AsinhLocator(linear_width=1, numticks=3,
523523
symthresh=0.25, base=0)

lib/matplotlib/ticker.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2636,13 +2636,13 @@ def set_params(self, numticks=None, symthresh=None,
26362636
self.subs = subs if len(subs) > 0 else None
26372637

26382638
def __call__(self):
2639-
dmin, dmax = self.axis.get_data_interval()
2640-
if (dmin * dmax) < 0 and abs(1 + dmax / dmin) < self.symthresh:
2639+
vmin, vmax = self.axis.get_view_interval()
2640+
if (vmin * vmax) < 0 and abs(1 + vmax / vmin) < self.symthresh:
26412641
# Data-range appears to be almost symmetric, so round up:
2642-
bound = max(abs(dmin), abs(dmax))
2642+
bound = max(abs(vmin), abs(vmax))
26432643
return self.tick_values(-bound, bound)
26442644
else:
2645-
return self.tick_values(dmin, dmax)
2645+
return self.tick_values(vmin, vmax)
26462646

26472647
def tick_values(self, vmin, vmax):
26482648
# Construct a set of "on-screen" locations
@@ -2660,7 +2660,9 @@ def tick_values(self, vmin, vmax):
26602660
xs = self.linear_width * np.sinh(ys / self.linear_width)
26612661
zero_xs = (ys == 0)
26622662

2663-
# Round the data-space values to be intuitive base-n numbers:
2663+
# Round the data-space values to be intuitive base-n numbers,
2664+
# keeping track of positive and negative values separately,
2665+
# but giving careful treatment to the zero value:
26642666
if self.base > 1:
26652667
log_base = math.log(self.base)
26662668
powers = (

0 commit comments

Comments
 (0)