Skip to content

Commit

Permalink
a few 3d bug fixes
Browse files Browse the repository at this point in the history
svn path=/trunk/matplotlib/; revision=2507
  • Loading branch information
cmoad committed Jun 22, 2006
1 parent 606ddd6 commit 4fa9418
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 129 deletions.
6 changes: 4 additions & 2 deletions examples/simple3d_oo.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,16 @@ def plot3d(self):
plt = self.fig.axes.append(ax3d)

delta = nx.pi / 100.0
u = nx.arange(0, 2*nx.pi + delta, delta)
v = nx.arange(0, nx.pi + delta, delta)
u = nx.arange(0, 2*nx.pi, delta)
v = nx.arange(0, nx.pi, delta)

x=10*nx.outerproduct(nx.cos(u),nx.sin(v))
y=10*nx.outerproduct(nx.sin(u),nx.sin(v))
z=10*nx.outerproduct(nx.ones(nx.size(u)),nx.cos(v))

ax3d.plot_wireframe(x,y,z)
ax3d.plot_surface(x+10,y,z)

ax3d.set_xlabel('X')
ax3d.set_ylabel('Y')
ax3d.set_zlabel('Z')
Expand Down
28 changes: 2 additions & 26 deletions lib/matplotlib/art3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@
from cm import jet

import numerix as nx

import proj3d


class Wrap2D:
"""Wrapper which wraps a 2D object and makes it 3D
Expand Down Expand Up @@ -85,7 +83,6 @@ class Text3D(Text3DW):
def __init__(self, x=0,y=0,z=0,text='', dir='z'):
inst = text.Text(x,y,text,*args, **kwargs)
Text3DW.__init__(self, z,dir, inst)


class oText3D(text.Text):
def __init__(self, x=0,y=0,z=0,text='', dir='z', *args, **kwargs):
Expand Down Expand Up @@ -115,7 +112,6 @@ def draw(self, renderer):

lines.Line2D.draw(self, renderer)


class Line3DCollectionW(Wrap2D):
def __init__(self, inst, segments):
Wrap2D.__init__(self, inst)
Expand All @@ -134,7 +130,6 @@ def __init__(self, segments, *args, **kwargs):
inst = LineCollection(segments, *args, **kwargs)
Line3DCollectionW.__init__(self, inst, segments)


class Line2DCollectionW(Wrap2D):
def __init__(self, inst, z=0, dir='z'):
Wrap2D.__init__(self, inst)
Expand Down Expand Up @@ -177,9 +172,7 @@ def get_verts(*args):

self.get_verts = get_verts
self.draw2d(renderer)




class Patch3DCollectionW(Wrap2D):
def __init__(self, inst, zs, dir='z'):
Wrap2D.__init__(self, inst)
Expand All @@ -202,7 +195,6 @@ def draw3d(self, renderer):
self._edgecolors = zalpha(self._edgecolors,vzs)
self._offsets = zip(vxs,vys)
self.draw2d(renderer)


class Poly3DCollectionW(Wrap2D):
def __init__(self, inst, zs=None, dir='z'):
Expand All @@ -225,8 +217,6 @@ def draw3d(self, renderer):
# mess with colors
self._verts = [verts for (z,verts) in vverts]
self.draw2d(renderer)



class oLine3DCollection(LineCollection):
def __init__(self, segments, *args, **kwargs):
Expand All @@ -243,7 +233,6 @@ def draw(self, renderer):
LineCollection.draw(self, renderer)
self._segments = orig_segments


class Poly3DCollection(Wrap2D):
def __init__(self, segments, *args, **kwargs):
inst = PolyCollection(segments, *args, **kwargs)
Expand Down Expand Up @@ -290,7 +279,6 @@ def draw3d(self, renderer):

self.draw2d(renderer)


def juggle_axes(xs,ys,zs, dir):
"""Depending on the direction of the plot re-order the axis
Expand All @@ -314,8 +302,6 @@ def draw3d(self, renderer):
self._x = xs
self._y = ys
self.draw2d(renderer)



def line_draw(self, renderer):
"""Draw a 2D line as a 3D line"""
Expand Down Expand Up @@ -360,8 +346,6 @@ def set_line_data(line, xs,ys,zs):
line.set_data(xs,ys)
line.zs = zs



def iscolor(c):
try:
return (len(c)==4 or len(c)==3) and (type(c[0])==float)
Expand Down Expand Up @@ -409,7 +393,6 @@ def patch_draw(self, renderer):
def wrap_patch(patch, zs, dir='z'):
return Patch3DCollectionW(patch, zs, dir)


def draw_linec(self, renderer):
orig_segments = self._segments
segments_3d = [[(x,y,z) for (x,y),z in zip(points,zs)]
Expand All @@ -436,8 +419,7 @@ def draw_polyc(self, renderer):
self._verts = segments_2d
PolyCollection.draw(self, renderer)
self._verts = orig_segments



def text_draw(self, renderer):
x,y = self.get_position()
xs,ys,zs = juggle_axes(x,y,self._z,self.dir)
Expand All @@ -459,7 +441,6 @@ def wrapped_draw(renderer,text=text):
def set_text_data(text, x,y,z):
text._x,text._y,text._z = x,y,z


def draw(text, renderer):
print 'call draw text', text
print text.get_visible()
Expand All @@ -474,7 +455,6 @@ def draw_text(renderer,text=text):
draw(text,renderer)
text.draw = draw_text


def wrap_2d_fn(patch, zs,dir='z',fn=patch_draw):
patch.zs = zs
patch.dir = dir
Expand All @@ -483,7 +463,3 @@ def wrapped_draw(renderer,patch=patch,fn=fn):
return fn(patch,renderer)
patch.draw = wrapped_draw
return patch




50 changes: 9 additions & 41 deletions lib/matplotlib/axes3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
"""
3D projection glued onto 2D Axes.
AXes3D
Axes3D
"""

import random
Expand All @@ -23,7 +20,6 @@
import numerix as nx
from colors import normalize


import art3d
import proj3d
import axis3d
Expand All @@ -36,7 +32,6 @@ def sensible_format_data(self, value):
else:
return '%4.3f' % value


class Axes3DI(Axes):
"""Wrap an Axes object
Expand All @@ -52,18 +47,13 @@ class Axes3DI(Axes):
The axes representing the x,y,z world dimensions are self.w_xaxis,
self.w_yaxis and self.w_zaxis. They can probably be controlled in
more or less the normal ways.
"""
def __init__(self, fig=None, rect=[0.0, 0.0, 1.0, 1.0], *args, **kwargs):
#
self.fig = fig or figure.Figure()
def __init__(self, fig, rect=[0.0, 0.0, 1.0, 1.0], *args, **kwargs):
self.fig = fig

azim = cbook.popd(kwargs, 'azim', -60)
elev = cbook.popd(kwargs, 'elev', 30)

#

self.xy_viewLim = unit_bbox()
self.zz_viewLim = unit_bbox()
self.xy_dataLim = unit_bbox()
Expand All @@ -74,19 +64,12 @@ def __init__(self, fig=None, rect=[0.0, 0.0, 1.0, 1.0], *args, **kwargs):
Axes.__init__(self, self.fig, rect,
frameon=True,
xticks=[], yticks=[], *args, **kwargs)
#
# figmanager = pylab.get_current_fig_manager()
# self.toolbar = figmanager.toolbar
#
#
# self.toolbar._active is current zoom/pan mode
#
#

self.M = None
self._ready = 1

self.view_init(elev, azim)
#self.mouse_init()
self.mouse_init()
self.create_axes()
self.set_top_view()

Expand All @@ -95,7 +78,6 @@ def __init__(self, fig=None, rect=[0.0, 0.0, 1.0, 1.0], *args, **kwargs):
#self.axesPatch.set_facecolor((0,0,0,0))
self.fig.add_axes(self)


def set_top_view(self):
# this happens to be the right view for the viewing coordinates
# moved up and to the left slightly to fit labels and axes
Expand Down Expand Up @@ -131,7 +113,6 @@ def nset_ylim(self, *args):
vmin,vmax = self.vlim_argument(self.get_ylim)
print 'ylim', vmin,vmax


def create_axes(self):
self.w_xaxis = axis3d.Axis('x',self.xy_viewLim.intervalx,
self.xy_dataLim.intervalx, self)
Expand All @@ -140,7 +121,6 @@ def create_axes(self):
self.w_zaxis = axis3d.Axis('z',self.zz_viewLim.intervalx,
self.zz_dataLim.intervalx, self)


def unit_cube(self,vals=None):
minx,maxx,miny,maxy,minz,maxz = vals or self.get_w_lims()
xs,ys,zs = ([minx,maxx,maxx,minx,minx,maxx,maxx,minx],
Expand Down Expand Up @@ -174,8 +154,6 @@ def tunit_edges(self, vals=None,M=None):
return edges

def draw(self, renderer):
#print 'elev', self.elev, 'azim', self.azim

# draw the background patch
self.axesPatch.draw(renderer)
self._frameon = False
Expand Down Expand Up @@ -273,7 +251,6 @@ def get_w_xlim(self):
def get_w_ylim(self):
return self.xy_viewLim.intervaly().get_bounds()


def pany(self, numsteps):
print 'numsteps', numsteps

Expand Down Expand Up @@ -336,7 +313,6 @@ def get_proj(self):
def mouse_init(self):
self.button_pressed = None
self.figure.canvas.mpl_connect('motion_notify_event', self.on_move)

self.figure.canvas.mpl_connect('button_press_event', self.button_press)
self.figure.canvas.mpl_connect('button_release_event', self.button_release)

Expand Down Expand Up @@ -380,7 +356,6 @@ def format_zdata(self, z):
fmt = self.w_zaxis.get_major_formatter()
return sensible_format_data(fmt,z)


def format_coord(self, xd, yd):
"""Given the 2D view coordinates attempt to guess a 3D coordinate
Expand Down Expand Up @@ -418,7 +393,6 @@ def on_move(self, event):
button-1 rotates
button-3 zooms
"""
#NOTE - this shouldn't be called before the graph has been drawn for the first time!
if event.inaxes != self or not self.M:
Expand All @@ -440,7 +414,7 @@ def on_move(self, event):
w = (x1-x0)
h = (y1-y0)
self.sx,self.sy = x,y
#

if self.button_pressed == 1:
# rotate viewing point
# get the x and y pixel coords
Expand Down Expand Up @@ -472,7 +446,6 @@ def on_move(self, event):
self.get_proj()
self.figure.canvas.draw()


def set_xlabel(self, xlabel, fontdict=None, **kwargs):
#par = cbook.popd(kwargs, 'par',None)
#label.set_par(par)
Expand All @@ -497,7 +470,6 @@ def set_zlabel(self, zlabel, fontdict=None, **kwargs):
label.update(kwargs)
return label


def plot(self, *args, **kwargs):
had_data = self.has_data()

Expand Down Expand Up @@ -561,7 +533,7 @@ def plot_surface(self, X, Y, Z, *args, **kwargs):
n = proj3d.cross(box[0]-box[1],
box[0]-box[2])
n = n/proj3d.mod(n)*5
shade.append(proj3d.dot(n,[-1,-1,0.5]))
shade.append(nx.dot(n,[-1,-1,0.5]))
lines.append((box[0],n+box[0]))
#
color = nx.array([0,0,1,1])
Expand Down Expand Up @@ -676,11 +648,9 @@ class Axes3D:
to their 3D approximations.
This should probably be the case for plot etc...
"""
def __init__(self, *args, **kwargs):
self.__dict__['wrapped'] = Axes3DI(*args, **kwargs)
def __init__(self, fig, *args, **kwargs):
self.__dict__['wrapped'] = Axes3DI(fig, *args, **kwargs)

def set_xlim(self, *args, **kwargs):
self.wrapped.set_w_xlim(*args, **kwargs)
Expand Down Expand Up @@ -713,7 +683,6 @@ def scatter(self, xs,ys,zs=None,dir='z',*args,**kwargs):
patches = art3d.wrap_patch(patches, zs=[0]*len(xs),dir=dir)
return patches


def bar(self, left, height, z=0, dir='z', *args, **kwargs):
had_data = self.has_data()
patches = self.wrapped.bar(left, height, *args, **kwargs)
Expand All @@ -729,7 +698,6 @@ def bar(self, left, height, z=0, dir='z', *args, **kwargs):
xs,ys,zs=art3d.juggle_axes(xs,ys,zs,dir)
self.wrapped.auto_scale_xyz(xs,ys,zs, had_data)


def test_scatter():

ax = Axes3D()
Expand Down
Loading

0 comments on commit 4fa9418

Please sign in to comment.