Index: matplotlib/axes.py
===================================================================
RCS file: /cvsroot/matplotlib/matplotlib/matplotlib/axes.py,v
retrieving revision 1.12
diff -c -r1.12 axes.py
*** matplotlib/axes.py	20 Oct 2003 14:44:13 -0000	1.12
--- matplotlib/axes.py	21 Oct 2003 01:12:02 -0000
***************
*** 9,16 ****
  
  import math, re, sys
  
! from Numeric import arange, array, ones, zeros, logical_and, \
!      nonzero, take, Float, transpose, log, asarray
  
  from cbook import iterable, is_string_like, flatten, enumerate
  from mlab import linspace
--- 9,16 ----
  
  import math, re, sys
  
! from Numeric import arange, array, asarray, ones, zeros, logical_and, \
!      nonzero, take, Float, transpose, log10
  
  from cbook import iterable, is_string_like, flatten, enumerate
  from mlab import linspace
***************
*** 60,72 ****
              if len(ind)<len(x):
                  print >>sys.stderr, 'log scale warning, negative data ignored'
                  x = take(x, ind)
!             return log(x)
  
              
          self._scale = 'linear'
          self._scalemap = {'linear' : identity,
                            'log' : logwarn}
-         self._scalefunc = self._scalemap[self._scale]
          self._gridOn = 1
          # I want to create persistent refs to the ticklines,
          # ticklabels and grid lines.  So I am creating a large number
--- 60,71 ----
              if len(ind)<len(x):
                  print >>sys.stderr, 'log scale warning, negative data ignored'
                  x = take(x, ind)
!             return log10(x)
  
              
          self._scale = 'linear'
          self._scalemap = {'linear' : identity,
                            'log' : logwarn}
          self._gridOn = 1
          # I want to create persistent refs to the ticklines,
          # ticklabels and grid lines.  So I am creating a large number
***************
*** 171,195 ****
          return self._left, self._right, self._width, self._height
  
      def get_view_distance(self):
!         'Return the distance max(viewlim) - min(viewlim)'
          if self._dataLim is None:
!             vmin, vmax = self._scalefunc(array(self.get_view_lim()))
!             return vmax - vmin
!         if self._viewLim is None:
!             return self.get_data_distance()
          else:
!             return self._viewLim[1] - self._viewLim[0]
  
      def get_view_lim(self):
          'Return the view limits as tuple min(viewlim), max(viewlim)'
          if self._dataLim is None:
!             lim = -1,1
!             return lim
!         if self._viewLim is None:
              lim = self.get_data_lim()
          else:
              lim =  self._viewLim
          assert(lim is not None)
          return lim
  
      def get_window_distance(self):
--- 170,205 ----
          return self._left, self._right, self._width, self._height
  
      def get_view_distance(self):
!         """Return the distance max(viewlim) - min(viewlim)"""
!         scale_func = self._scalemap[self._scale]
          if self._dataLim is None:
!             vmin, vmax = scale_func(asarray(self.get_view_lim()))
!         elif self._viewLim is None:
!             # XXX ADS: this path is broken. The call to
!             # self.get_data_lim() will fail if self._dataLim is None.
!             # #(I kept it as intact as possible.)
!             dmin, dmax = self.get_data_lim()
!             vmin, vmax = scale_func(array((dmin,dmax)))
          else:
!             vminvmax = scale_func(array(self._viewLim))
!             if len(vminvmax) < 2:
!                 raise NotImplementedError("No support for case of invalid log axis range")
!             vmin, vmax = vminvmax
!         return vmax - vmin
  
      def get_view_lim(self):
          'Return the view limits as tuple min(viewlim), max(viewlim)'
          if self._dataLim is None:
!             if self._scale == 'linear':
!                 lim = -1,1
!             else:
!                 lim = 0.1,1
!         elif self._viewLim is None:
              lim = self.get_data_lim()
          else:
              lim =  self._viewLim
          assert(lim is not None)
+         lim = self._scalemap[self._scale](asarray(lim))
          return lim
  
      def get_window_distance(self):
***************
*** 211,233 ****
          "Get the tick locations in data coordinates as a Numeric array"
          if self._ticklocs is not None:
              return self._ticklocs
-         
-         numticks = self.get_numticks()
- 
-         if numticks==0: return []
          vmin, vmax = self.get_view_lim()
!         d = self.get_view_distance()
!         if numticks==1: 0.5*d
!         step = d/(numticks-1)
!         # add a small offset to include endpoint
!         ticklocs = arange(vmin, vmax+0.1*d, step)
          return ticklocs
  
      def get_ticklocs_win(self):
          "Get the tick locations in window coordinates as a Numeric array"
          if self._ticklocs is None:
!             wmin, wmax = self.get_window_lim()
!             return linspace(wmin, wmax, self.get_numticks())
          else:
              return self.transform_to_display(self._ticklocs)
  
--- 221,256 ----
          "Get the tick locations in data coordinates as a Numeric array"
          if self._ticklocs is not None:
              return self._ticklocs
          vmin, vmax = self.get_view_lim()
!         if self._scale == 'linear':
!             numticks = self.get_numticks()
!             if numticks==0: return []
!             ticklocs = linspace(vmin, vmax, numticks)
!         elif self._scale == 'log':
!             ticklocs = []
!             for decade_start in 10.0**arange(math.floor(vmin),math.ceil(vmax)):
!                 ticklocs.append(decade_start)
!                 ticklocs.extend( arange(2,10)*decade_start )
!             ticklocs.append(10*decade_start)
!             ticklocs = array(ticklocs)
!             ind = nonzero(ticklocs>=10.0**vmin)
!             ticklocs = take(ticklocs,ind)
!             ind = nonzero(ticklocs<=10.0**vmax)
!             ticklocs = take(ticklocs,ind)
!             ticklocs = log10(ticklocs)
          return ticklocs
  
      def get_ticklocs_win(self):
          "Get the tick locations in window coordinates as a Numeric array"
          if self._ticklocs is None:
!             if self._scale == 'linear':
!                 return self.transform_to_display(self.get_ticklocs())
!             elif self._scale == 'log':
!                 v = self.get_ticklocs()
!                 if iterable(v) and len(v)==0: return v
!                 vmin, vmax = self.get_view_lim()
!                 wmin, wmax = self.get_window_lim()
!                 return (wmax-wmin)/(vmax-vmin)*(v-vmin)+wmin
          else:
              return self.transform_to_display(self._ticklocs)
  
***************
*** 288,298 ****
          artists.append(self._label)
          return artists
  
- 
      def set_data_lim(self, dmin, dmax):
          'Set the data limits to dmin, dmax'
          self._dataLim = [dmin, dmax]
  
      def set_ticks(self, ticks):
          'Set the locations of the tick marks from sequence ticks'
          ticks = asarray(ticks)
--- 311,325 ----
          artists.append(self._label)
          return artists
  
      def set_data_lim(self, dmin, dmax):
          'Set the data limits to dmin, dmax'
          self._dataLim = [dmin, dmax]
  
+     def set_scale(self, value):
+         if value not in self._scalemap.keys():
+             raise ValueError('scale must be in %s'%str(self._scalemap.keys()))
+         self._scale = value
+ 
      def set_ticks(self, ticks):
          'Set the locations of the tick marks from sequence ticks'
          ticks = asarray(ticks)
***************
*** 352,358 ****
          if iterable(v) and len(v)==0: return v
          vmin, vmax = self.get_view_lim()
          wmin, wmax = self.get_window_lim()
!         v = self._scalefunc(v)
          return (wmax-wmin)/(vmax-vmin)*(v-vmin)+wmin
  
  
--- 379,385 ----
          if iterable(v) and len(v)==0: return v
          vmin, vmax = self.get_view_lim()
          wmin, wmax = self.get_window_lim()
!         v = self._scalemap[self._scale](v)
          return (wmax-wmin)/(vmax-vmin)*(v-vmin)+wmin
  
  
***************
*** 398,403 ****
--- 425,433 ----
      def format_tickval(self, x):
          'Format the number x as a string'
          d = self.get_view_distance()
+         if self._scale == 'log':
+             x = 10**x
+             
          #if the number is not too big and it's an int, format it as an
          #int
          if abs(x)<1e4 and x==int(x): return '%d' % x
***************
*** 460,465 ****
--- 490,497 ----
  
      def get_numticks(self):
          if self._ticklocs is None:
+             if self._scale == 'log':
+                 return len(self.get_ticklocs()) # XXX ADS: make faster
              if self._width is None: return 0
              win = self._width/self._dpi # width of axes in inches
              if win>4: return 11
***************
*** 549,554 ****
--- 581,588 ----
  
      def get_numticks(self):
          if self._ticklocs is None:
+             if self._scale == 'log':
+                 return len(self.get_ticklocs()) # XXX ADS: make faster
              if self._height is None: return 0
              hin = self._height/self._dpi  # height of axes in inches
              if hin>4: return 11
***************
*** 917,923 ****
          return self._xaxis.get_ticklabels()
  
      def get_xticks(self):
!         "Return the y ticks as a list of locations"
          return self._xaxis.get_ticklocs()
  
  
--- 951,957 ----
          return self._xaxis.get_ticklabels()
  
      def get_xticks(self):
!         "Return the x ticks as a list of locations"
          return self._xaxis.get_ticklocs()
  
  
***************
*** 1126,1131 ****
--- 1160,1171 ----
  
      def set_axis_on(self):
          self.axison = True
+ 
+     def set_xscale(self,value):
+         self._xaxis.set_scale(value)
+ 
+     def set_yscale(self,value):
+         self._yaxis.set_scale(value)
  
      def scatter(self, x, y, s=None, c='b'):
          """
  
