Skip to content

[ENH] Add data parameter in Axes3D.plot #30270

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

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
37 changes: 19 additions & 18 deletions lib/mpl_toolkits/mplot3d/axes3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -1963,43 +1963,44 @@ def text(self, x, y, z, s, zdir=None, *, axlim_clip=False, **kwargs):
text3D = text
text2D = Axes.text

def plot(self, xs, ys, *args, zdir='z', axlim_clip=False, **kwargs):
@_preprocess_data(replace_names=['xs', 'ys', 'zs'])
def plot(self, xs, ys, zs=0, fmt=None, *, zdir='z', axlim_clip=False, **kwargs):
"""
Plot 2D or 3D data.

Parameters
----------
.. versionchanged:: 3.10
xs : 1D array-like
x coordinates of vertices.
ys : 1D array-like
y coordinates of vertices.
zs : float or 1D array-like
z coordinates of vertices; either one for all points or one for
each point.
The signature was changed to make the parameters *zs* and *fmt* explicit.

The unconventional but previously valid call signature
``plot(xs, ys, 'ro', zs=zs)`` is no longer supported.

Parameters
----------
zdir : {'x', 'y', 'z'}, default: 'z'
When plotting 2D data, the direction to use as z.
axlim_clip : bool, default: False
Whether to hide data that is outside the axes view limits.

.. versionadded:: 3.10
data : indexable object, optional
DATA_PARAMETER_PLACEHOLDER
**kwargs
Other arguments are forwarded to `matplotlib.axes.Axes.plot`.
Other arguments are forwarded to 'Axes.plot'.
Comment on lines -1971 to +1993
Copy link
Member

Choose a reason for hiding this comment

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

Um, you've significantly mixed up the docstring:

  • moved the ..versionchanged:: 3.10 from axlim_clip to the top
  • moved the xs, ys, zs out of the Parameters section
  • Removed the link in **kwargs

Please take more care when submitting changes. These are all aspects that you should have been able to detect yourself and not something we should be spending valuable reviewer time on.

"""
had_data = self.has_data()

# `zs` can be passed positionally or as keyword; checking whether
# args[0] is a string matches the behavior of 2D `plot` (via
# `_process_plot_var_args`).
if args and not isinstance(args[0], str):
zs, *args = args
if 'zs' in kwargs:
raise TypeError("plot() for multiple values for argument 'zs'")
else:
zs = kwargs.pop('zs', 0)

xs, ys, zs = cbook._broadcast_with_masks(xs, ys, zs)

lines = super().plot(xs, ys, *args, **kwargs)
if fmt is not None:
lines = super().plot(xs, ys, fmt, **kwargs)
else:
lines = super().plot(xs, ys, **kwargs)

for line in lines:
art3d.line_2d_to_3d(line, zs=zs, zdir=zdir, axlim_clip=axlim_clip)

Expand Down Expand Up @@ -4042,7 +4043,7 @@ def stem(self, x, y, z, *, linefmt='C0-', markerfmt='C0o', basefmt='C3-',
linestyle = mpl._val_or_rc(linestyle, 'lines.linestyle')

# Plot everything in required order.
baseline, = self.plot(basex, basey, basefmt, zs=bottom,
baseline, = self.plot(basex, basey, zs=bottom, fmt=basefmt,
zdir=orientation, label='_nolegend_')
stemlines = art3d.Line3DCollection(
lines, linestyles=linestyle, colors=linecolor, label='_nolegend_',
Expand Down
14 changes: 12 additions & 2 deletions lib/mpl_toolkits/mplot3d/tests/test_axes3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,9 +346,19 @@
@check_figures_equal()
def test_plot_scalar(fig_test, fig_ref):
ax1 = fig_test.add_subplot(projection='3d')
ax1.plot([1], [1], "o")
ax1.plot([1], [1], [1], "o")
ax1.plot([2], [2], "o")
ax2 = fig_ref.add_subplot(projection='3d')
ax2.plot(1, 1, "o")
ax2.plot(1, 1, 1, "o")
ax2.plot(2, 2, 0, "o")

Check warning on line 353 in lib/mpl_toolkits/mplot3d/tests/test_axes3d.py

View check run for this annotation

Codecov / codecov/patch

lib/mpl_toolkits/mplot3d/tests/test_axes3d.py#L352-L353

Added lines #L352 - L353 were not covered by tests


@check_figures_equal()
def test_plot_data(fig_test, fig_ref):
ax1 = fig_test.add_subplot(projection='3d')
ax1.plot([1, 2, 3], [4, 5, 6], [7, 8, 9])
ax2 = fig_ref.add_subplot(projection='3d')
ax2.plot([1, 2, 3], [4, 5, 6], [7, 8, 9])


def test_invalid_line_data():
Expand Down
4 changes: 2 additions & 2 deletions lib/mpl_toolkits/mplot3d/tests/test_legend3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
def test_legend_plot():
fig, ax = plt.subplots(subplot_kw=dict(projection='3d'))
x = np.arange(10)
ax.plot(x, 5 - x, 'o', zdir='y', label='z=1')
ax.plot(x, x - 5, 'o', zdir='y', label='z=-1')
ax.plot(x, 5 - x, 0, fmt='o', zdir='y', label='z=1')
ax.plot(x, x - 5, 0, fmt='o', zdir='y', label='z=-1')
ax.legend()


Expand Down
Loading