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

Skip to content

Commit c0e089d

Browse files
authored
Merge pull request #31260 from scottshambaugh/3d_semilog
MNT: Raise NotImplementedError for 3D semilog plots
2 parents d5f597d + d15441a commit c0e089d

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"""
3232

3333
from collections import defaultdict
34+
from functools import partialmethod
3435
import itertools
3536
import math
3637
import textwrap
@@ -1196,6 +1197,17 @@ def set_zscale(self, value, **kwargs):
11961197
"""
11971198
self._set_axis_scale(self.zaxis, value, **kwargs)
11981199

1200+
def _raise_semilog_not_implemented(self, name, *args, **kwargs):
1201+
raise NotImplementedError(
1202+
f"Axes3D does not support {name}. Use ax.set_xscale/set_yscale/set_zscale "
1203+
"and ax.plot(...) instead."
1204+
)
1205+
1206+
semilogx = partialmethod(_raise_semilog_not_implemented, "semilogx")
1207+
semilogy = partialmethod(_raise_semilog_not_implemented, "semilogy")
1208+
semilogz = partialmethod(_raise_semilog_not_implemented, "semilogz")
1209+
loglog = partialmethod(_raise_semilog_not_implemented, "loglog")
1210+
11991211
get_zticks = _axis_method_wrapper("zaxis", "get_ticklocs")
12001212
set_zticks = _axis_method_wrapper("zaxis", "set_ticks")
12011213
get_zmajorticklabels = _axis_method_wrapper("zaxis", "get_majorticklabels")

lib/mpl_toolkits/mplot3d/tests/test_axes3d.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3169,6 +3169,15 @@ def test_scale3d_autoscale_with_log():
31693169
assert lim[1] > 0, f"{name} upper limit should be positive"
31703170

31713171

3172+
@pytest.mark.parametrize("method", ["semilogx", "semilogy", "semilogz", "loglog"])
3173+
def test_semilog_loglog_not_implemented(method):
3174+
"""semilogx/y/z and loglog should raise NotImplementedError on Axes3D."""
3175+
fig = plt.figure()
3176+
ax = fig.add_subplot(projection='3d')
3177+
with pytest.raises(NotImplementedError, match="Axes3D does not support"):
3178+
getattr(ax, method)([1, 10, 100], [1, 2, 3])
3179+
3180+
31723181
def test_scale3d_calc_coord():
31733182
"""_calc_coord should return data coordinates with correct pane values."""
31743183
fig = plt.figure()

0 commit comments

Comments
 (0)