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

Skip to content

Commit bc26389

Browse files
committed
FIX: Disallow twinx/twiny on Axes3D
Closes matplotlib#31522. The root cause is that Axes3D inherits a lot of functionality from Axes that does not work for 3D. This is a design flaw we cannot easily fix. With this PR we have at least a reasonable mechanism in place to flag not-supported methods. When we get aware of additional methods, we can easily add them.
1 parent e6cab33 commit bc26389

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ class Axes3D(Axes):
7171
As a user, you do not instantiate Axes directly, but use Axes creation
7272
methods instead; e.g. from `.pyplot` or `.Figure`:
7373
`~.pyplot.subplots`, `~.pyplot.subplot_mosaic` or `.Figure.add_axes`.
74+
75+
.. note::
76+
77+
Some of the inherited behavior of Axes is not applicable to 3d and will raise
78+
a `NotImplementedError`.
7479
"""
7580
name = '3d'
7681

@@ -1197,10 +1202,18 @@ def set_zscale(self, value, **kwargs):
11971202
"""
11981203
self._set_axis_scale(self.zaxis, value, **kwargs)
11991204

1205+
def _raise_not_implemented(self, name, *args, **kwargs):
1206+
raise NotImplementedError(f"Axes3D does not support '{name}'.")
1207+
1208+
twinx = partialmethod(_raise_not_implemented, "twinx")
1209+
twiny = partialmethod(_raise_not_implemented, "twiny")
1210+
secondary_xaxis = partialmethod(_raise_not_implemented, "secondary_xaxis")
1211+
secondary_yaxis = partialmethod(_raise_not_implemented, "secondary_yaxis")
1212+
12001213
def _raise_semilog_not_implemented(self, name, *args, **kwargs):
12011214
raise NotImplementedError(
1202-
f"Axes3D does not support {name}. Use ax.set_xscale/set_yscale/set_zscale "
1203-
"and ax.plot(...) instead."
1215+
f"Axes3D does not support '{name}'. "
1216+
"Use ax.set_xscale/set_yscale/set_zscale and ax.plot(...) instead."
12041217
)
12051218

12061219
semilogx = partialmethod(_raise_semilog_not_implemented, "semilogx")

0 commit comments

Comments
 (0)