From 20c39b534394bc4d2e6f4cd6cf26e89d88667e8e Mon Sep 17 00:00:00 2001 From: "fabrizio.benedetti.82" Date: Thu, 11 Feb 2010 13:20:54 +0000 Subject: [PATCH] Scale of axis are now in engineering format. --- hooke.py | 11 ++++++++++ libhooke.py | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/hooke.py b/hooke.py index 6046847..6bceecb 100755 --- a/hooke.py +++ b/hooke.py @@ -1,4 +1,5 @@ #!/usr/bin/env python +# -*- coding: utf-8 -*- ''' HOOKE - A force spectroscopy review & analysis tool @@ -260,6 +261,11 @@ class MainWindow(wx.Frame): self.figures=[control.get_figure() for control in self.controls] self.axes=[figure.gca() for figure in self.figures] + for i in range(len(self.axes)): + self.axes[i].xaxis.set_major_formatter(EngrFormatter()) + self.axes[i].yaxis.set_major_formatter(EngrFormatter(2)) + + self.cpanels[1].Hide() self.mainpanel.splitter.Initialize(self.cpanels[0]) @@ -540,6 +546,11 @@ class MainWindow(wx.Frame): ylim=self.axes[dest].get_ylim() self.axes[dest].set_ylim((ylim[1],ylim[0])) + for i in range(len(self.axes)): + self.axes[i].xaxis.set_major_formatter(EngrFormatter()) + self.axes[i].yaxis.set_major_formatter(EngrFormatter(2)) + + self.controls[dest].draw() diff --git a/libhooke.py b/libhooke.py index f668635..5da0508 100755 --- a/libhooke.py +++ b/libhooke.py @@ -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 -- 2.26.2