Open
Description
Problem
Add data parameter in Axes3D.plot like Axes.plot
Proposed solution
Change de plot like :
def plot(self, xs, ys, *args, zdir='z', axlim_clip=False, data=None, **kwargs):
"""
Plot 2D or 3D data.
Parameters
----------
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.
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
An object with labelled data. If given, provide the label names to
plot in *x*, *y* and *z*.
**kwargs
Other arguments are forwarded to `matplotlib.axes.Axes.plot`.
"""
had_data = self.has_data()
# Use data parameter like 2d plot.
if data:
xs=data[xs]
ys=data[ys]
if 'zs' in kwargs:
zs=kwargs.pop('zs')
else:
zs,*args= args
zs=data[zs]
# `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`).
elif 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)
for line in lines:
art3d.line_2d_to_3d(line, zs=zs, zdir=zdir, axlim_clip=axlim_clip)
xs, ys, zs = art3d.juggle_axes(xs, ys, zs, zdir)
self.auto_scale_xyz(xs, ys, zs, had_data)
return lines
Add test in test_axes3d.py
@check_figures_equal()
def test_plot_data(fig_test, fig_ref):
ax1 = fig_test.add_subplot(projection='3d')
ax1.plot('x','y','r',data=dict(x=[1,2,3],y=[4,5,6],r=[7,8,9]))
ax2 = fig_ref.add_subplot(projection='3d')
ax2.plot([1,2,3],[4,5,6],[7,8,9])