Skip to content

Commit 8143153

Browse files
committed
Improved testing of locator edge-cases, and patched constrained_layout misstep
1 parent 76d9b42 commit 8143153

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

examples/scales/asinh_demo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@
5959

6060
########################################
6161
# Compare "asinh" graphs with different scale parameter "linear_width":
62-
fig2 = plt.figure()
63-
axs = fig2.subplots(1, 3, sharex=True, constrained_layout=True)
62+
fig2 = plt.figure(constrained_layout=True)
63+
axs = fig2.subplots(1, 3, sharex=True)
6464
for ax, a0 in zip(axs, (0.2, 1.0, 5.0)):
6565
ax.set_title('linear_width={:.3g}'.format(a0))
6666
ax.plot(x, x, label='y=x')

lib/matplotlib/scale.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,8 @@ def __init__(self, axis, *, linear_width=1.0, **kwargs):
512512
Parameters
513513
----------
514514
linear_width : float, default: 1
515-
The scale parameter defining the extent of the quasi-linear region,
515+
The scale parameter (elsewhere referred to as :math:`a_0`)
516+
defining the extent of the quasi-linear region,
516517
and the coordinate values beyond which the transformation
517518
becomes asympoticially logarithmic.
518519
"""

lib/matplotlib/tests/test_ticker.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,18 @@ def test_wide_values(self):
477477
[-1000, -100, -20, -3, -0.4,
478478
0, 0.4, 3, 20, 100, 1000])
479479

480+
def test_near_zero(self):
481+
"""Check that manually injected zero will supersede nearby tick"""
482+
lctr = mticker.AsinhLocator(linear_width=100, numticks=3)
483+
484+
assert_almost_equal(lctr.tick_values(-1.1, 0.9), [ -1.0, 0.0, 0.9])
485+
486+
def test_fallback(self):
487+
lctr = mticker.AsinhLocator(1.0, numticks=11)
488+
489+
assert_almost_equal(lctr.tick_values(100, 101),
490+
np.arange(100, 101.01, 0.1))
491+
480492

481493
class TestScalarFormatter:
482494
offset_data = [

lib/matplotlib/ticker.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2639,9 +2639,10 @@ def tick_values(self, vmin, vmax):
26392639
+ zero_xs*1e-6))))
26402640
)
26412641
qs = decades * np.round(xs / decades)
2642+
ticks = np.array(sorted(set(qs)))
26422643

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

0 commit comments

Comments
 (0)