From d15441a3427be2c6cd0389cb2205d59e298617b3 Mon Sep 17 00:00:00 2001 From: Scott Shambaugh Date: Mon, 9 Mar 2026 14:23:42 -0600 Subject: [PATCH] Raise NotImplementedError for 3D semilog plots --- lib/mpl_toolkits/mplot3d/axes3d.py | 12 ++++++++++++ lib/mpl_toolkits/mplot3d/tests/test_axes3d.py | 9 +++++++++ 2 files changed, 21 insertions(+) diff --git a/lib/mpl_toolkits/mplot3d/axes3d.py b/lib/mpl_toolkits/mplot3d/axes3d.py index c6e28ec71b78..7d0a5ae009c4 100644 --- a/lib/mpl_toolkits/mplot3d/axes3d.py +++ b/lib/mpl_toolkits/mplot3d/axes3d.py @@ -31,6 +31,7 @@ """ from collections import defaultdict +from functools import partialmethod import itertools import math import textwrap @@ -1196,6 +1197,17 @@ def set_zscale(self, value, **kwargs): """ self._set_axis_scale(self.zaxis, value, **kwargs) + def _raise_semilog_not_implemented(self, name, *args, **kwargs): + raise NotImplementedError( + f"Axes3D does not support {name}. Use ax.set_xscale/set_yscale/set_zscale " + "and ax.plot(...) instead." + ) + + semilogx = partialmethod(_raise_semilog_not_implemented, "semilogx") + semilogy = partialmethod(_raise_semilog_not_implemented, "semilogy") + semilogz = partialmethod(_raise_semilog_not_implemented, "semilogz") + loglog = partialmethod(_raise_semilog_not_implemented, "loglog") + get_zticks = _axis_method_wrapper("zaxis", "get_ticklocs") set_zticks = _axis_method_wrapper("zaxis", "set_ticks") get_zmajorticklabels = _axis_method_wrapper("zaxis", "get_majorticklabels") diff --git a/lib/mpl_toolkits/mplot3d/tests/test_axes3d.py b/lib/mpl_toolkits/mplot3d/tests/test_axes3d.py index b953fd415955..8d2441393dde 100644 --- a/lib/mpl_toolkits/mplot3d/tests/test_axes3d.py +++ b/lib/mpl_toolkits/mplot3d/tests/test_axes3d.py @@ -3169,6 +3169,15 @@ def test_scale3d_autoscale_with_log(): assert lim[1] > 0, f"{name} upper limit should be positive" +@pytest.mark.parametrize("method", ["semilogx", "semilogy", "semilogz", "loglog"]) +def test_semilog_loglog_not_implemented(method): + """semilogx/y/z and loglog should raise NotImplementedError on Axes3D.""" + fig = plt.figure() + ax = fig.add_subplot(projection='3d') + with pytest.raises(NotImplementedError, match="Axes3D does not support"): + getattr(ax, method)([1, 10, 100], [1, 2, 3]) + + def test_scale3d_calc_coord(): """_calc_coord should return data coordinates with correct pane values.""" fig = plt.figure()