Scale of axis are now in engineering format.
authorfabrizio.benedetti.82 <devnull@localhost>
Thu, 11 Feb 2010 13:20:54 +0000 (13:20 +0000)
committerfabrizio.benedetti.82 <devnull@localhost>
Thu, 11 Feb 2010 13:20:54 +0000 (13:20 +0000)
hooke.py
libhooke.py

index 6046847bb54c767b8745a2219c42a037beaac1e4..6bceecbd5d6043c30c2f971b0821d2f01c609a17 100755 (executable)
--- a/hooke.py
+++ b/hooke.py
@@ -1,4 +1,5 @@
 #!/usr/bin/env python\r
+# -*- coding: utf-8 -*-\r
 \r
 '''\r
 HOOKE - A force spectroscopy review & analysis tool\r
@@ -260,6 +261,11 @@ class MainWindow(wx.Frame):
         self.figures=[control.get_figure() for control in self.controls]\r
         self.axes=[figure.gca() for figure in self.figures]\r
 \r
+       for i in range(len(self.axes)):\r
+         self.axes[i].xaxis.set_major_formatter(EngrFormatter())\r
+         self.axes[i].yaxis.set_major_formatter(EngrFormatter(2))\r
+\r
+\r
         self.cpanels[1].Hide()\r
         self.mainpanel.splitter.Initialize(self.cpanels[0])\r
 \r
@@ -540,6 +546,11 @@ class MainWindow(wx.Frame):
                 ylim=self.axes[dest].get_ylim()        \r
                 self.axes[dest].set_ylim((ylim[1],ylim[0])) \r
 \r
+           for i in range(len(self.axes)):\r
+             self.axes[i].xaxis.set_major_formatter(EngrFormatter())\r
+             self.axes[i].yaxis.set_major_formatter(EngrFormatter(2))\r
+\r
+\r
             self.controls[dest].draw()\r
 \r
 \r
index f668635fab64650f2a2dc3f39df8775545d42d4b..5da0508a918660d38b84736883e5b3f1b8ac32e7 100755 (executable)
@@ -1,4 +1,5 @@
 #!/usr/bin/env python
+# -*- coding: utf-8 -*-
 
 '''
 libhooke.py
@@ -24,6 +25,8 @@ import xml.dom.minidom
 import os
 import string
 import csv
+from matplotlib.ticker import ScalarFormatter
+
 
 HOOKE_VERSION=['0.8.3_devel', 'Seinei', '2008-04-16']
 WX_GOOD=['2.6','2.8'] 
@@ -251,6 +254,62 @@ class HookeConfig:
         pass    
 
 
+class EngrFormatter(ScalarFormatter):
+    """A variation of the standard ScalarFormatter, using only multiples of 
+three
+in the mantissa. A fixed number of decimals can be displayed with the optional 
+parameter `ndec` . If `ndec` is None (default), the number of decimals is 
+defined
+from the current ticks.
+    """
+    def __init__(self, ndec=None, useOffset=True, useMathText=False):
+        ScalarFormatter.__init__(self, useOffset, useMathText)
+        if ndec is None or ndec < 0:
+            self.format = None
+        elif ndec == 0:
+            self.format = "%d"
+        else:
+            self.format = "%%1.%if" % ndec
+    #........................
+
+    def _set_orderOfMagnitude(self, mrange):
+           """Sets the order of magnitude."""        
+           locs = numpy.absolute(self.locs)
+           if self.offset: 
+               oom = numpy.floor(numpy.log10(mrange))
+           else:
+               if locs[0] > locs[-1]: 
+                   val = locs[-1]
+               else: 
+                   val = locs[0]
+               if val == 0: 
+                   oom = 0
+               else: 
+                   oom = numpy.floor(numpy.log10(val))
+           if oom <= -3:
+               self.orderOfMagnitude = 3*(oom//3)
+           elif oom <= -1:
+               self.orderOfMagnitude = -3
+           elif oom >= 4:
+               self.orderOfMagnitude = 3*(oom//3)
+           else:
+               self.orderOfMagnitude = 0
+
+
+    #........................
+    def _set_format(self):
+        """Sets the format string to format all ticklabels."""
+        # set the format string to format all the ticklabels
+        locs = (numpy.array(self.locs)-self.offset) /  10**self.orderOfMagnitude+1e-15
+        sigfigs = [len(str('%1.3f'% loc).split('.')[1].rstrip('0')) \
+                   for loc in locs]
+        sigfigs.sort()
+        if self.format is None:
+            self.format = '%1.' + str(sigfigs[-1]) + 'f'
+        if self._usetex or self._useMathText: self.format = '$%s$'%self.format
+
+
+
 class ClickedPoint:
     '''
     this class defines what a clicked point on the curve plot is