Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Update x,y.z values for an existing Line3D object #1629

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

Closed
wants to merge 5 commits into from
Closed
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
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -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:

Expand Down
24 changes: 22 additions & 2 deletions lib/mpl_toolkits/mplot3d/art3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,19 @@ 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._verts3d = 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
# ever been drawn, these are the projected (x,y)
# see draw()
xs = self.get_xdata()
ys = self.get_ydata()

Expand All @@ -112,6 +117,21 @@ def set_3d_properties(self, zs=0, zdir='z'):
pass
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
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]
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)
Expand Down