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 4 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.
33 changes: 33 additions & 0 deletions lib/mpl_toolkits/mplot3d/art3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,39 @@ 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.


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
Copy link
Member

Choose a reason for hiding this comment

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

Does this need to un-juggle the order of the data?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It probably should. We're calling set_3d_properties with no zdir so we shouldn't do any juggling but the user could change the zdir, I'll probably also allow an optional kwarg to allow the user to also set zdir right from set_data_3d.

Copy link
Member
8000

Choose a reason for hiding this comment

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

Both should probably get the zdir kwarg?

Copy link
Member

Choose a reason for hiding this comment

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

The juggle axis feature is for converting a 2D object into 3D. It essentially states which dimension is going to be a constant. It is not applicable here.


@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