From ecbc43e693d707764b34dfef17dca21522713866 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell <“tcaswell@gmail.com”> Date: Sun, 30 Dec 2012 23:15:27 -0600 Subject: [PATCH 1/5] added a set_3d_data function to Line3D which works in the same spirit as set_xdata and set_ydata for Line2D, but requires _all_ of the data to be set in one go (to not have to write the caching layer of Line2D again yet). --- lib/mpl_toolkits/mplot3d/art3d.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/mpl_toolkits/mplot3d/art3d.py b/lib/mpl_toolkits/mplot3d/art3d.py index 53ba0fe2e559..d80a92517493 100644 --- a/lib/mpl_toolkits/mplot3d/art3d.py +++ b/lib/mpl_toolkits/mplot3d/art3d.py @@ -99,9 +99,12 @@ def __init__(self, xs, ys, zs, *args, **kwargs): Keyword arguments are passed onto :func:`~matplotlib.lines.Line2D`. ''' lines.Line2D.__init__(self, [], [], *args, **kwargs) - self._verts3d = xs, ys, zs + self.set_3d_data(xs,ys,zs) def set_3d_properties(self, zs=0, zdir='z'): + # this is broken, because if the line has + # ever been drawn, these are the projected (x,y) + # see draw() xs = self.get_xdata() ys = self.get_ydata() @@ -112,6 +115,14 @@ def set_3d_properties(self, zs=0, zdir='z'): pass self._verts3d = juggle_axes(xs, ys, zs, zdir) + def set_3d_data(self, xs, ys, zs, zdir='z'): + try: + zs = float(zs) + zs = [zs for x in xs] + except: + pass + self._verts3d = juggle_axes(xs, ys, zs, zdir) + def draw(self, renderer): xs3d, ys3d, zs3d = self._verts3d xs, ys, zs = proj3d.proj_transform(xs3d, ys3d, zs3d, renderer.M) From 2bd8fae0a983a929a2fb016353e840b3aae2c61c Mon Sep 17 00:00:00 2001 From: Thomas A Caswell <“tcaswell@gmail.com”> Date: Sun, 30 Dec 2012 23:19:52 -0600 Subject: [PATCH 2/5] Added zdir kwarg to Line3D.__init__ --- lib/mpl_toolkits/mplot3d/art3d.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/mpl_toolkits/mplot3d/art3d.py b/lib/mpl_toolkits/mplot3d/art3d.py index d80a92517493..f3b55914ed15 100644 --- a/lib/mpl_toolkits/mplot3d/art3d.py +++ b/lib/mpl_toolkits/mplot3d/art3d.py @@ -94,12 +94,14 @@ class Line3D(lines.Line2D): 3D line object. ''' - def __init__(self, xs, ys, zs, *args, **kwargs): + def __init__(self, xs, ys, zs, zdir='z', *args, **kwargs): ''' + *zdir* sets with axes to treat as 'z' + Keyword arguments are passed onto :func:`~matplotlib.lines.Line2D`. ''' lines.Line2D.__init__(self, [], [], *args, **kwargs) - self.set_3d_data(xs,ys,zs) + self.set_3d_data(xs, ys, zs, zdir) def set_3d_properties(self, zs=0, zdir='z'): # this is broken, because if the line has From f82812dbd3f417b86c583679797f85a100af9a72 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell <“tcaswell@gmail.com”> Date: Sun, 30 Dec 2012 23:43:47 -0600 Subject: [PATCH 3/5] added default values to Line3D.set_3d_data so that a sub-set of x,y,z can be specified. --- lib/mpl_toolkits/mplot3d/art3d.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/mpl_toolkits/mplot3d/art3d.py b/lib/mpl_toolkits/mplot3d/art3d.py index f3b55914ed15..b099f1317bc3 100644 --- a/lib/mpl_toolkits/mplot3d/art3d.py +++ b/lib/mpl_toolkits/mplot3d/art3d.py @@ -117,7 +117,14 @@ def set_3d_properties(self, zs=0, zdir='z'): pass self._verts3d = juggle_axes(xs, ys, zs, zdir) - def set_3d_data(self, xs, ys, zs, zdir='z'): + def set_3d_data(self, xs=None, ys=None, zs=None, zdir='z'): + x_old,y_old,z_old = self._verts3d + if xs is None: + xs = x_old + if ys is None: + ys = y_old + if zs is None: + zs = z_old try: zs = float(zs) zs = [zs for x in xs] From 0602dfd09462f66e7c7fd93c218d80a1642997a5 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell <“tcaswell@gmail.com”> Date: Mon, 31 Dec 2012 10:57:26 -0600 Subject: [PATCH 4/5] pep8 compliance --- lib/mpl_toolkits/mplot3d/art3d.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mpl_toolkits/mplot3d/art3d.py b/lib/mpl_toolkits/mplot3d/art3d.py index b099f1317bc3..804506cd2c72 100644 --- a/lib/mpl_toolkits/mplot3d/art3d.py +++ b/lib/mpl_toolkits/mplot3d/art3d.py @@ -118,7 +118,7 @@ def set_3d_properties(self, zs=0, zdir='z'): self._verts3d = juggle_axes(xs, ys, zs, zdir) def set_3d_data(self, xs=None, ys=None, zs=None, zdir='z'): - x_old,y_old,z_old = self._verts3d + x_old, y_old, z_old = self._verts3d if xs is None: xs = x_old if ys is None: From 3f5fc85f6360636098ced35da5d269353015ee6c Mon Sep 17 00:00:00 2001 From: Thomas A Caswell <“tcaswell@gmail.com”> Date: Mon, 31 Dec 2012 11:00:01 -0600 Subject: [PATCH 5/5] added CHANGELOG entry for set_3d_data --- CHANGELOG | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 352c176fa11b..5e0fa014ac13 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,6 @@ +2012-12-31 Added set_3d_data to Line3D to update the data of an existing + Line3d object. - TAC + 2012-12-05 Added MatplotlibDeprecationWarning class for signaling deprecation. Matplotlib developers can use this class as follows: