66"""
773D projection glued onto 2D Axes.
88
9- AXes3D
10-
11-
12-
9+ Axes3D
1310"""
1411
1512import random
2320import numerix as nx
2421from colors import normalize
2522
26-
2723import art3d
2824import proj3d
2925import axis3d
@@ -36,7 +32,6 @@ def sensible_format_data(self, value):
3632 else :
3733 return '%4.3f' % value
3834
39-
4035class Axes3DI (Axes ):
4136 """Wrap an Axes object
4237
@@ -52,18 +47,13 @@ class Axes3DI(Axes):
5247 The axes representing the x,y,z world dimensions are self.w_xaxis,
5348 self.w_yaxis and self.w_zaxis. They can probably be controlled in
5449 more or less the normal ways.
55-
56-
5750 """
58- def __init__ (self , fig = None , rect = [0.0 , 0.0 , 1.0 , 1.0 ], * args , ** kwargs ):
59- #
60- self .fig = fig or figure .Figure ()
51+ def __init__ (self , fig , rect = [0.0 , 0.0 , 1.0 , 1.0 ], * args , ** kwargs ):
52+ self .fig = fig
6153
6254 azim = cbook .popd (kwargs , 'azim' , - 60 )
6355 elev = cbook .popd (kwargs , 'elev' , 30 )
6456
65- #
66-
6757 self .xy_viewLim = unit_bbox ()
6858 self .zz_viewLim = unit_bbox ()
6959 self .xy_dataLim = unit_bbox ()
@@ -74,19 +64,12 @@ def __init__(self, fig=None, rect=[0.0, 0.0, 1.0, 1.0], *args, **kwargs):
7464 Axes .__init__ (self , self .fig , rect ,
7565 frameon = True ,
7666 xticks = [], yticks = [], * args , ** kwargs )
77- #
78- # figmanager = pylab.get_current_fig_manager()
79- # self.toolbar = figmanager.toolbar
80- #
81- #
82- # self.toolbar._active is current zoom/pan mode
83- #
84- #
67+
8568 self .M = None
8669 self ._ready = 1
8770
8871 self .view_init (elev , azim )
89- # self.mouse_init()
72+ self .mouse_init ()
9073 self .create_axes ()
9174 self .set_top_view ()
9275
@@ -95,7 +78,6 @@ def __init__(self, fig=None, rect=[0.0, 0.0, 1.0, 1.0], *args, **kwargs):
9578 #self.axesPatch.set_facecolor((0,0,0,0))
9679 self .fig .add_axes (self )
9780
98-
9981 def set_top_view (self ):
10082 # this happens to be the right view for the viewing coordinates
10183 # moved up and to the left slightly to fit labels and axes
@@ -131,7 +113,6 @@ def nset_ylim(self, *args):
131113 vmin ,vmax = self .vlim_argument (self .get_ylim )
132114 print 'ylim' , vmin ,vmax
133115
134-
135116 def create_axes (self ):
136117 self .w_xaxis = axis3d .Axis ('x' ,self .xy_viewLim .intervalx ,
137118 self .xy_dataLim .intervalx , self )
@@ -140,7 +121,6 @@ def create_axes(self):
140121 self .w_zaxis = axis3d .Axis ('z' ,self .zz_viewLim .intervalx ,
141122 self .zz_dataLim .intervalx , self )
142123
143-
144124 def unit_cube (self ,vals = None ):
145125 minx ,maxx ,miny ,maxy ,minz ,maxz = vals or self .get_w_lims ()
146126 xs ,ys ,zs = ([minx ,maxx ,maxx ,minx ,minx ,maxx ,maxx ,minx ],
@@ -174,8 +154,6 @@ def tunit_edges(self, vals=None,M=None):
174154 return edges
175155
176156 def draw (self , renderer ):
177- #print 'elev', self.elev, 'azim', self.azim
178-
179157 # draw the background patch
180158 self .axesPatch .draw (renderer )
181159 self ._frameon = False
@@ -273,7 +251,6 @@ def get_w_xlim(self):
273251 def get_w_ylim (self ):
274252 return self .xy_viewLim .intervaly ().get_bounds ()
275253
276-
277254 def pany (self , numsteps ):
278255 print 'numsteps' , numsteps
279256
@@ -336,7 +313,6 @@ def get_proj(self):
336313 def mouse_init (self ):
337314 self .button_pressed = None
338315 self .figure .canvas .mpl_connect ('motion_notify_event' , self .on_move )
339-
340316 self .figure .canvas .mpl_connect ('button_press_event' , self .button_press )
341317 self .figure .canvas .mpl_connect ('button_release_event' , self .button_release )
342318
@@ -380,7 +356,6 @@ def format_zdata(self, z):
380356 fmt = self .w_zaxis .get_major_formatter ()
381357 return sensible_format_data (fmt ,z )
382358
383-
384359 def format_coord (self , xd , yd ):
385360 """Given the 2D view coordinates attempt to guess a 3D coordinate
386361
@@ -418,7 +393,6 @@ def on_move(self, event):
418393
419394 button-1 rotates
420395 button-3 zooms
421-
422396 """
423397 #NOTE - this shouldn't be called before the graph has been drawn for the first time!
424398 if event .inaxes != self or not self .M :
@@ -440,7 +414,7 @@ def on_move(self, event):
440414 w = (x1 - x0 )
441415 h = (y1 - y0 )
442416 self .sx ,self .sy = x ,y
443- #
417+
444418 if self .button_pressed == 1 :
445419 # rotate viewing point
446420 # get the x and y pixel coords
@@ -472,7 +446,6 @@ def on_move(self, event):
472446 self .get_proj ()
473447 self .figure .canvas .draw ()
474448
475-
476449 def set_xlabel (self , xlabel , fontdict = None , ** kwargs ):
477450 #par = cbook.popd(kwargs, 'par',None)
478451 #label.set_par(par)
@@ -497,7 +470,6 @@ def set_zlabel(self, zlabel, fontdict=None, **kwargs):
497470 label .update (kwargs )
498471 return label
499472
500-
501473 def plot (self , * args , ** kwargs ):
502474 had_data = self .has_data ()
503475
@@ -561,7 +533,7 @@ def plot_surface(self, X, Y, Z, *args, **kwargs):
561533 n = proj3d .cross (box [0 ]- box [1 ],
562534 box [0 ]- box [2 ])
563535 n = n / proj3d .mod (n )* 5
564- shade .append (proj3d .dot (n ,[- 1 ,- 1 ,0.5 ]))
536+ shade .append (nx .dot (n ,[- 1 ,- 1 ,0.5 ]))
565537 lines .append ((box [0 ],n + box [0 ]))
566538 #
567539 color = nx .array ([0 ,0 ,1 ,1 ])
@@ -676,11 +648,9 @@ class Axes3D:
676648 to their 3D approximations.
677649
678650 This should probably be the case for plot etc...
679-
680-
681651 """
682- def __init__ (self , * args , ** kwargs ):
683- self .__dict__ ['wrapped' ] = Axes3DI (* args , ** kwargs )
652+ def __init__ (self , fig , * args , ** kwargs ):
653+ self .__dict__ ['wrapped' ] = Axes3DI (fig , * args , ** kwargs )
684654
685655 def set_xlim (self , * args , ** kwargs ):
686656 self .wrapped .set_w_xlim (* args , ** kwargs )
@@ -713,7 +683,6 @@ def scatter(self, xs,ys,zs=None,dir='z',*args,**kwargs):
713683 patches = art3d .wrap_patch (patches , zs = [0 ]* len (xs ),dir = dir )
714684 return patches
715685
716-
717686 def bar (self , left , height , z = 0 , dir = 'z' , * args , ** kwargs ):
718687 had_data = self .has_data ()
719688 patches = self .wrapped .bar (left , height , * args , ** kwargs )
@@ -729,7 +698,6 @@ def bar(self, left, height, z=0, dir='z', *args, **kwargs):
729698 xs ,ys ,zs = art3d .juggle_axes (xs ,ys ,zs ,dir )
730699 self .wrapped .auto_scale_xyz (xs ,ys ,zs , had_data )
731700
732-
733701def test_scatter ():
734702
735703 ax = Axes3D ()
0 commit comments