Skip to content

Make zdir key-word only for 3D-scatter and -bar #27538

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
11 changes: 6 additions & 5 deletions lib/mpl_toolkits/mplot3d/axes3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -2590,8 +2590,8 @@ def add_collection3d(self, col, zs=0, zdir='z'):
@_preprocess_data(replace_names=["xs", "ys", "zs", "s",
"edgecolors", "c", "facecolor",
"facecolors", "color"])
def scatter(self, xs, ys, zs=0, zdir='z', s=20, c=None, depthshade=True,
*args, **kwargs):
@_api.make_keyword_only("3.9", "zdir")
def scatter(self, xs, ys, zs=0, zdir='z', s=20, c=None, depthshade=True, **kwargs):
"""
Create a scatter plot.

Expand Down Expand Up @@ -2653,7 +2653,7 @@ def scatter(self, xs, ys, zs=0, zdir='z', s=20, c=None, depthshade=True,
if np.may_share_memory(zs_orig, zs): # Avoid unnecessary copies.
zs = zs.copy()

patches = super().scatter(xs, ys, s=s, c=c, *args, **kwargs)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and below at super.bar(), are we sure that the super class method can't use any *args? Don't want to break any plots that rely on it if so.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory yes: https://matplotlib.org/devdocs/api/_as_gen/matplotlib.axes.Axes.scatter.html#matplotlib.axes.Axes.scatter

but very unlikely in practice. One would have to pass all 3D positional parameters

scatter(self, xs, ys, zs, zdir, s, c, depthshade, ...)

and then continue with the non-overlapping 2D positional parameters, minimally:

scatter(self, xs, ys, zs, zdir, s, c, depthshade, marker)

I would be very surprised if somebody took the effort to figure that out.

I'm inclined to allow tolerate minimal breakage here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me!

patches = super().scatter(xs, ys, s=s, c=c, **kwargs)
art3d.patch_collection_2d_to_3d(patches, zs=zs, zdir=zdir,
depthshade=depthshade)

Expand All @@ -2667,7 +2667,8 @@ def scatter(self, xs, ys, zs=0, zdir='z', s=20, c=None, depthshade=True,
scatter3D = scatter

@_preprocess_data()
def bar(self, left, height, zs=0, zdir='z', *args, **kwargs):
@_api.make_keyword_only("3.9", "zdir")
def bar(self, left, height, zs=0, zdir='z', **kwargs):
"""
Add 2D bar(s).

Expand All @@ -2694,7 +2695,7 @@ def bar(self, left, height, zs=0, zdir='z', *args, **kwargs):
"""
had_data = self.has_data()

patches = super().bar(left, height, *args, **kwargs)
patches = super().bar(left, height, **kwargs)

zs = np.broadcast_to(zs, len(left), subok=True)

Expand Down