8000 Add set_data_3d and get_data_3d to Line3d by Raab70 · Pull Request #10111 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Add set_data_3d and get_data_3d to Line3d #10111

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

Merged
merged 5 commits into from
Jan 8, 2019
Merged
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions doc/users/next_whats_new/2018_01_02_line3d_get_set_data.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
mplot3d Line3D now allows {set,get}_data_3d
-------------------------------------------

Lines created with the 3d projection in mplot3d can now access the data using
``mplot3d.art3d.Line3D.get_data_3d()`` which returns a tuple of array_likes containing
the (x, y, z) data. The equivalent ``mplot3d.art3d.Line3D.set_data_3d(x, y, z)``
can be used to modify the data of an existing Line3D.
34 changes: 34 additions & 0 10000 deletions lib/mpl_toolkits/mplot3d/art3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,40 @@ def set_3d_properties(self, zs=0, zdir='z'):
self._verts3d = juggle_axes(xs, ys, zs, zdir)
self.stale = True

def set_data_3d(self, *args):
"""
Set the x, y and z data

Parameters
----------
x : array_like
The x-data to be plotted
y : array_like
The y-data to be plotted
z : array_like
The z-data to be plotted

Notes
-----
Accepts x, y, z arguments or a single array_like (x, y, z)
"""
if len(args) == 1:
self._verts3d = args[0]
else:
self._verts3d = args
Copy link
Member

Choose a reason for hiding this comment

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

I think you need to add self.stale = True here.

self.stale = True

def get_data_3d(self):
"""
Get the current data

Returns
-------
verts3d : length-3 tuple or array_likes
The current data as a tuple or array_likes
"""
return self._verts3d

@artist.allow_rasterization
def draw(self, renderer):
xs3d, ys3d, zs3d = self._verts3d
Expand Down
12 changes: 12 additions & 0 deletions lib/mpl_toolkits/tests/test_mplot3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,18 @@ def test_calling_conventions(self):
ax.voxels(filled=filled, x=x, y=y, z=z)


def test_line3d_set_get_data_3d():
x, y, z = [0, 1], [2, 3], [4, 5]
x2, y2, z2 = [6, 7], [8, 9], [10, 11]
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
lines = ax.plot(x, y, z)
line = lines[0]
np.testing.assert_array_equal((x, y, z), line.get_data_3d())
line.set_data_3d(x2, y2, z2)
np.testing.assert_array_equal((x2, y2, z2), line.get_data_3d())


def test_inverted_cla():
# Github PR #5450. Setting autoscale should reset
# axes to be non-inverted.
Expand Down
0