diff --git a/lib/mpl_toolkits/mplot3d/axes3d.py b/lib/mpl_toolkits/mplot3d/axes3d.py index 55b204022fb9..620f35a7fd3d 100644 --- a/lib/mpl_toolkits/mplot3d/axes3d.py +++ b/lib/mpl_toolkits/mplot3d/axes3d.py @@ -1963,12 +1963,12 @@ 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 @@ -1976,30 +1976,31 @@ def plot(self, xs, ys, *args, zdir='z', axlim_clip=False, **kwargs): 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'. """ 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) @@ -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_', diff --git a/lib/mpl_toolkits/mplot3d/tests/test_axes3d.py b/lib/mpl_toolkits/mplot3d/tests/test_axes3d.py index cd45c8e33a6f..b2b33db164a0 100644 --- a/lib/mpl_toolkits/mplot3d/tests/test_axes3d.py +++ b/lib/mpl_toolkits/mplot3d/tests/test_axes3d.py @@ -346,9 +346,19 @@ def test_lines3d(): @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_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(): diff --git a/lib/mpl_toolkits/mplot3d/tests/test_legend3d.py b/lib/mpl_toolkits/mplot3d/tests/test_legend3d.py index 7fd676df1e31..af50d72185b7 100644 --- a/lib/mpl_toolkits/mplot3d/tests/test_legend3d.py +++ b/lib/mpl_toolkits/mplot3d/tests/test_legend3d.py @@ -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()