8000 Merge pull request #10111 from Raab70/bug-fix/line3d · matplotlib/matplotlib@c044780 · GitHub
[go: up one dir, main page]

Skip to content

Commit c044780

Browse files
authored
Merge pull request #10111 from Raab70/bug-fix/line3d
ENH: Add set_data_3d and get_data_3d to Line3d
2 parents 4614a26 + 4f2ae55 commit c044780

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
mplot3d Line3D now allows {set,get}_data_3d
2+
-------------------------------------------
3+
4+
Lines created with the 3d projection in mplot3d can now access the data using
5+
``mplot3d.art3d.Line3D.get_data_3d()`` which returns a tuple of array_likes containing
6+
the (x, y, z) data. The equivalent ``mplot3d.art3d.Line3D.set_data_3d(x, y, z)``
7+
can be used to modify the data of an existing Line3D.

lib/mpl_toolkits/mplot3d/art3d.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,40 @@ def set_3d_properties(self, zs=0, zdir='z'):
150150
self._verts3d = juggle_axes(xs, ys, zs, zdir)
151151
self.stale = True
152152

153+
def set_data_3d(self, *args):
154+
"""
155+
Set the x, y and z data
156+
157+
Parameters
158+
----------
159+
x : array_like
160+
The x-data to be plotted
161+
y : array_like
162+
The y-data to be plotted
163+
z : array_like
164+
The z-data to be plotted
165+
166+
Notes
167+
-----
168+
Accepts x, y, z arguments or a single array_like (x, y, z)
169+
"""
170+
if len(args) == 1:
171+
self._verts3d = args[0]
172+
else:
173+
self._verts3d = args
174+
self.stale = True
175+
176+
def get_data_3d(self):
177+
"""
178+
Get the current data
179+
180+
Returns
181+
-------
182+
verts3d : length-3 tuple or array_likes
183+
The current data as a tuple or array_likes
184+
"""
185+
return self._verts3d
186+
153187
@artist.allow_rasterization
154188
def draw(self, renderer):
155189
xs3d, ys3d, zs3d = self._verts3d

lib/mpl_toolkits/tests/test_mplot3d.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,18 @@ def test_calling_conventions(self):
815815
ax.voxels(filled=filled, x=x, y=y, z=z)
816816

817817

818+
def test_line3d_set_get_data_3d():
819+
x, y, z = [0, 1], [2, 3], [4, 5]
820+
x2, y2, z2 = [6, 7], [8, 9], [10, 11]
821+
fig = plt.figure()
822+
ax = fig.add_subplot(111, projection='3d')
823+
lines = ax.plot(x, y, z)
824+
line = lines[0]
825+
np.testing.assert_array_equal((x, y, z), line.get_data_3d())
826+
line.set_data_3d(x2, y2, z2)
827+
np.testing.assert_array_equal((x2, y2, z2), line.get_data_3d())
828+
829+
818830
def test_inverted_cla():
819831
# Github PR #5450. Setting autoscale should reset
820832
# axes to be non-inverted.

0 commit comments

Comments
 (0)
0