From a92dff47b051b99b313625b378fbf370512d76b2 Mon Sep 17 00:00:00 2001 From: Rob Harrigan Date: Tue, 26 Dec 2017 23:00:20 -0600 Subject: [PATCH 1/5] add set_data_3d method to Line3D --- lib/mpl_toolkits/mplot3d/art3d.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/mpl_toolkits/mplot3d/art3d.py b/lib/mpl_toolkits/mplot3d/art3d.py index 543e1b4c7a7d..d4ac3b7dc25e 100644 --- a/lib/mpl_toolkits/mplot3d/art3d.py +++ b/lib/mpl_toolkits/mplot3d/art3d.py @@ -151,6 +151,21 @@ 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 + + ACCEPTS: 3D array (rows are x, y, z) or three 1D arrays + """ + if len(args) == 1: + x, y, z = args[0] + else: + x, y, z = args + + self.set_xdata(x) + self.set_ydata(y) + self.set_3d_properties(zs=z) + @artist.allow_rasterization def draw(self, renderer): xs3d, ys3d, zs3d = self._verts3d From 93ac991f05635425fddbc331e832e27d98a00b61 Mon Sep 17 00:00:00 2001 From: Rob Harrigan Date: Tue, 26 Dec 2017 23:15:24 -0600 Subject: [PATCH 2/5] adding get_data_3d method to Line3d --- lib/mpl_toolkits/mplot3d/art3d.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/mpl_toolkits/mplot3d/art3d.py b/lib/mpl_toolkits/mplot3d/art3d.py index d4ac3b7dc25e..319b0fbd58a5 100644 --- a/lib/mpl_toolkits/mplot3d/art3d.py +++ b/lib/mpl_toolkits/mplot3d/art3d.py @@ -166,6 +166,12 @@ def set_data_3d(self, *args): self.set_ydata(y) self.set_3d_properties(zs=z) + def get_data_3d(self): + """ + Return the xdata, ydata, zdata. + """ + return self._verts3d + @artist.allow_rasterization def draw(self, renderer): xs3d, ys3d, zs3d = self._verts3d From 635e5dc7dbc1c54500312199a42bbf56fa06a253 Mon Sep 17 00:00:00 2001 From: Rob Harrigan Date: Tue, 2 Jan 2018 15:19:31 -0600 Subject: [PATCH 3/5] remove juggle_3d and update to numpydoc --- lib/mpl_toolkits/mplot3d/art3d.py | 28 ++++++++++++++++++-------- lib/mpl_toolkits/tests/test_mplot3d.py | 12 +++++++++++ 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/lib/mpl_toolkits/mplot3d/art3d.py b/lib/mpl_toolkits/mplot3d/art3d.py index 319b0fbd58a5..8302ac817e37 100644 --- a/lib/mpl_toolkits/mplot3d/art3d.py +++ b/lib/mpl_toolkits/mplot3d/art3d.py @@ -155,20 +155,32 @@ def set_data_3d(self, *args): """ Set the x, y and z data - ACCEPTS: 3D array (rows are x, y, z) or three 1D arrays + 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: - x, y, z = args[0] + self._verts3d = args[0] else: - x, y, z = args - - self.set_xdata(x) - self.set_ydata(y) - self.set_3d_properties(zs=z) + self._verts3d = args def get_data_3d(self): """ - Return the xdata, ydata, zdata. + Get the current data + + Returns + ------- + verts3d : length-3 tuple or array_likes + The current data as a tuple or array_likes """ return self._verts3d diff --git a/lib/mpl_toolkits/tests/test_mplot3d.py b/lib/mpl_toolkits/tests/test_mplot3d.py index 18a6a896fd83..5e2b2a6441bd 100644 --- a/lib/mpl_toolkits/tests/test_mplot3d.py +++ b/lib/mpl_toolkits/tests/test_mplot3d.py @@ -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. From 14f6f2e5278860058843a9f412d5133825f23ad0 Mon Sep 17 00:00:00 2001 From: Rob Harrigan Date: Tue, 2 Jan 2018 15:19:44 -0600 Subject: [PATCH 4/5] adding whats_next --- .../next_whats_new/2018_01_02_line3d_get_set_data.rst | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 doc/users/next_whats_new/2018_01_02_line3d_get_set_data.rst diff --git a/doc/users/next_whats_new/2018_01_02_line3d_get_set_data.rst b/doc/users/next_whats_new/2018_01_02_line3d_get_set_data.rst new file mode 100644 index 000000000000..38a9d7b85752 --- /dev/null +++ b/doc/users/next_whats_new/2018_01_02_line3d_get_set_data.rst @@ -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. From 4f2ae55b334554b93ab432c1fc8d28737c6812a5 Mon Sep 17 00:00:00 2001 From: Rob Harrigan Date: Tue, 7 Aug 2018 14:38:42 -0500 Subject: [PATCH 5/5] add stale mark when setting data --- lib/mpl_toolkits/mplot3d/art3d.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/mpl_toolkits/mplot3d/art3d.py b/lib/mpl_toolkits/mplot3d/art3d.py index 8302ac817e37..e4bd08b3e39d 100644 --- a/lib/mpl_toolkits/mplot3d/art3d.py +++ b/lib/mpl_toolkits/mplot3d/art3d.py @@ -172,6 +172,7 @@ def set_data_3d(self, *args): self._verts3d = args[0] else: self._verts3d = args + self.stale = True def get_data_3d(self): """