Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/matplotlib/mpl-data/matplotlibrc
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,9 @@
# will be used when it can remove
# at least this number of significant
# digits from tick labels.
#axes.formatter.legacy_symlog_ticker: True # Use legacy tick placement algorithm
# for symlog axes. May cause bad tick
# placement in some cases.

#axes.spines.left: True # display axis spines
#axes.spines.bottom: True
Expand Down
8 changes: 8 additions & 0 deletions lib/matplotlib/rcsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -1156,6 +1156,7 @@ def _convert_validator_spec(key, conv):
"axes.formatter.min_exponent": validate_int,
"axes.formatter.useoffset": validate_bool,
"axes.formatter.offset_threshold": validate_int,
"axes.formatter.legacy_symlog_ticker": validate_bool,
"axes.unicode_minus": validate_bool,
# This entry can be either a cycler object or a string repr of a
# cycler-object, which gets eval()'ed to create the object.
Expand Down Expand Up @@ -2014,6 +2015,13 @@ class _Param:
"remove at least this number of significant digits from tick "
"labels."
),
_Param(
"axes.formatter.legacy_symlog_ticker",
default=True,
validator=validate_bool,
description="When True, ticks in symlog axes are placed using legacy rules. "
"This is known to cause badly labeled axes in some cases."
),
_Param(
"axes.spines.left",
default=True,
Expand Down
6 changes: 4 additions & 2 deletions lib/matplotlib/scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ class SymmetricalLogScale(ScaleBase):
name = 'symlog'

@_make_axis_parameter_optional
def __init__(self, axis=None, *, base=10, linthresh=2, subs=None, linscale=1):
def __init__(self, axis=None, *, base=10, linthresh=2, subs='auto', linscale=1):
self._transform = SymmetricalLogTransform(base, linthresh, linscale)
self.subs = subs

Expand All @@ -553,7 +553,9 @@ def set_default_locators_and_formatters(self, axis):
axis.set_major_formatter(LogFormatterSciNotation(self.base))
axis.set_minor_locator(SymmetricalLogLocator(self.get_transform(),
self.subs))
axis.set_minor_formatter(NullFormatter())
axis.set_minor_formatter(
LogFormatterSciNotation(self.base,
labelOnlyBase=(self.subs != 'auto')))

def get_transform(self):
"""Return the `.SymmetricalLogTransform` associated with this scale."""
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/scale.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class SymmetricalLogScale(ScaleBase):
*,
base: float = ...,
linthresh: float = ...,
subs: Iterable[int] | None = ...,
subs: Iterable[int] | Literal["auto", "all"] | None = ...,
linscale: float = ...
) -> None: ...
@property
Expand Down
Binary file not shown.
Binary file not shown.
36 changes: 31 additions & 5 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1341,11 +1341,9 @@ def test_fill_between_interpolate_nan():
interpolate=True, alpha=0.5)


# test_symlog and test_symlog2 used to have baseline images in all three
# formats, but the png and svg baselines got invalidated by the removal of
# minor tick overstriking.
@image_comparison(['symlog.pdf'])
@image_comparison(['symlog_nolegacy.pdf'])
def test_symlog():
mpl.rcParams['axes.formatter.legacy_symlog_ticker'] = False
x = np.array([0, 1, 2, 4, 6, 9, 12, 24])
y = np.array([1000000, 500000, 100000, 100, 5, 0, 0, 0])

Expand All @@ -1356,8 +1354,36 @@ def test_symlog():
ax.set_ylim(-1, 10000000)


@image_comparison(['symlog2.pdf'], remove_text=True)
@image_comparison(['symlog2_nolegacy.pdf'], remove_text=True)
def test_symlog2():
mpl.rcParams['axes.formatter.legacy_symlog_ticker'] = False
# Numbers from -50 to 50, with 0.1 as step
x = np.arange(-50, 50, 0.001)

fig, axs = plt.subplots(5, 1)
for ax, linthresh in zip(axs, [20., 2., 1., 0.1, 0.01]):
ax.plot(x, x)
ax.set_xscale('symlog', linthresh=linthresh)
ax.grid(True)
axs[-1].set_ylim(-0.1, 0.1)


@image_comparison(['symlog.pdf'])
def test_legacy_symlog():
mpl.rcParams['axes.formatter.legacy_symlog_ticker'] = True
x = np.array([0, 1, 2, 4, 6, 9, 12, 24])
y = np.array([1000000, 500000, 100000, 100, 5, 0, 0, 0])

fig, ax = plt.subplots()
ax.plot(x, y)
ax.set_yscale('symlog')
ax.set_xscale('linear')
ax.set_ylim(-1, 10000000)


@image_comparison(['symlog2.pdf'], remove_text=True)
def test_legacy_symlog2():
mpl.rcParams['axes.formatter.legacy_symlog_ticker'] = True
# Numbers from -50 to 50, with 0.1 as step
x = np.arange(-50, 50, 0.001)

Expand Down
67 changes: 60 additions & 7 deletions lib/matplotlib/tests/test_ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,12 +608,62 @@ def test_set_params(self):
class TestSymmetricalLogLocator:
def test_set_params(self):
"""
Create symmetrical log locator with default subs =[1.0] numticks = 15,
Create symmetrical log locator with default subs=[1.0] numticks='auto',
and change it to something else.
See if change was successful.
Should not exception.
"""
sym = mticker.SymmetricalLogLocator(base=10, linthresh=1)
sym = mticker.SymmetricalLogLocator(base=10, linthresh=1, linscale=1,
legacy_symlog_ticker=False)
sym.set_params(subs=[2.0], numticks=8)
assert sym._subs == [2.0]
assert sym.numticks == 8

@pytest.mark.parametrize(
'vmin, vmax, expected',
[
(0, 1, [-1, 0, 1, 10]),
(-1, 1, [-10, -1, 0, 1, 10]),
],
)
def test_values(self, vmin, vmax, expected):
# https://github.com/matplotlib/matplotlib/issues/25945
sym = mticker.SymmetricalLogLocator(base=10, linthresh=1, linscale=1,
legacy_symlog_ticker=False)
ticks = sym.tick_values(vmin=vmin, vmax=vmax)
assert_array_equal(ticks, expected)

def test_subs(self):
sym = mticker.SymmetricalLogLocator(base=10, linthresh=1, linscale=1,
subs=[2.0, 4.0], legacy_symlog_ticker=False)
sym.create_dummy_axis()
sym.axis.set_view_interval(-10, 10)
assert_array_equal(sym(), [-400, -200, -40, -20, -4, -2, -0.4, -0.2, -0.1,
0.1, 0.2, 0.4, 2, 4, 20, 40, 200, 400])

def test_extending(self):
sym = mticker.SymmetricalLogLocator(base=10, linthresh=1, linscale=1,
legacy_symlog_ticker=False)
sym.create_dummy_axis()
sym.axis.set_view_interval(8, 9)
assert_array_equal(sym(), [1, 10])
sym.axis.set_view_interval(8, 12)
assert_array_equal(sym(), [1, 10, 100])
assert sym.view_limits(10, 10) == (1, 100)
assert sym.view_limits(-10, -10) == (-100, -1)
assert sym.view_limits(0, 0) == (-1, 1)


class TestLegacySymmetricalLogLocator:
def test_set_params(self):
"""
Create symmetrical log locator with default subs=[1.0] numticks='auto',
and change it to something else.
See if change was successful.
Should not exception.
"""
sym = mticker.SymmetricalLogLocator(base=10, linthresh=1, linscale=1,
legacy_symlog_ticker=True)
sym.set_params(subs=[2.0], numticks=8)
assert sym._subs == [2.0]
assert sym.numticks == 8
Expand All @@ -627,26 +677,29 @@ def test_set_params(self):
)
def test_values(self, vmin, vmax, expected):
# https://github.com/matplotlib/matplotlib/issues/25945
sym = mticker.SymmetricalLogLocator(base=10, linthresh=1)
sym = mticker.SymmetricalLogLocator(base=10, linthresh=1, linscale=1,
legacy_symlog_ticker=True)
ticks = sym.tick_values(vmin=vmin, vmax=vmax)
assert_array_equal(ticks, expected)

def test_subs(self):
sym = mticker.SymmetricalLogLocator(base=10, linthresh=1, subs=[2.0, 4.0])
sym = mticker.SymmetricalLogLocator(base=10, linthresh=1, linscale=1,
subs=[2.0, 4.0], legacy_symlog_ticker=True)
sym.create_dummy_axis()
sym.axis.set_view_interval(-10, 10)
assert_array_equal(sym(), [-20, -40, -2, -4, 0, 2, 4, 20, 40])
assert_array_equal(sym(), [-10, -1, 0, 1, 10])

def test_extending(self):
sym = mticker.SymmetricalLogLocator(base=10, linthresh=1)
sym = mticker.SymmetricalLogLocator(base=10, linthresh=1, linscale=1,
legacy_symlog_ticker=True)
sym.create_dummy_axis()
sym.axis.set_view_interval(8, 9)
assert (sym() == [1.0]).all()
sym.axis.set_view_interval(8, 12)
assert (sym() == [1.0, 10.0]).all()
assert sym.view_limits(10, 10) == (1, 100)
assert sym.view_limits(-10, -10) == (-100, -1)
assert sym.view_limits(0, 0) == (-0.001, 0.001)
assert sym.view_limits(0, 0) == (-1, 1)


class TestAsinhLocator:
Expand Down
Loading
Loading