+++ /dev/null
-# Copyright (C) 2006-2010 Francesco Musiani
-# Massimo Sandal <devicerandom@gmail.com>
-# W. Trevor King <wking@drexel.edu>
-#
-# This file is part of Hooke.
-#
-# Hooke is free software: you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation, either
-# version 3 of the License, or (at your option) any later version.
-#
-# Hooke is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with Hooke. If not, see
-# <http://www.gnu.org/licenses/>.
-
-"""A number formatting utilities for Hooke.
-"""
-
-from matplotlib.ticker import ScalarFormatter
-
-from . import curve as lhc
-
-
-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[0]
- else:
- val = locs[-1]
- 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
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas\r
from matplotlib.backends.backend_wx import NavigationToolbar2Wx as NavToolbar\r
from matplotlib.figure import Figure\r
-from matplotlib.ticker import Formatter\r
+from matplotlib.ticker import Formatter, ScalarFormatter\r
import wx\r
\r
from ....util.callback import callback, in_callback\r
return ppSI(value=x, unit=self.unit, decimals=self.decimals)\r
\r
\r
+class HookeScalarFormatter (ScalarFormatter):\r
+ """:class:`matplotlib.ticker.ScalarFormatter` using only multiples\r
+ of three in the mantissa.\r
+\r
+ A fixed number of decimals can be displayed with the optional\r
+ parameter `decimals` . If `decimals` is `None` (default), the number\r
+ of decimals is defined from the current ticks.\r
+ """\r
+ def __init__(self, decimals=None, **kwargs):\r
+ # Can't use super() because ScalarFormatter is an old-style class :(.\r
+ ScalarFormatter.__init__(self, **kwargs)\r
+ self._decimals = decimals\r
+\r
+ def _set_orderOfMagnitude(self, *args, **kwargs):\r
+ """Sets the order of magnitude.""" \r
+ # Can't use super() because ScalarFormatter is an old-style class :(.\r
+ ScalarFormatter._set_orderOfMagnitude(self, *args, **kwargs)\r
+ self.orderOfMagnitude -= self.orderOfMagnitude % 3\r
+\r
+ def _set_format(self, *args, **kwargs):\r
+ """Sets the format string to format all ticklabels."""\r
+ # Can't use super() because ScalarFormatter is an old-style class :(.\r
+ ScalarFormatter._set_format(self, *args, **kwargs)\r
+ if self._decimals is None or self._decimals < 0:\r
+ locs = (np.asarray(self.locs)-self.offset) / 10**self.orderOfMagnitude+1e-15\r
+ sigfigs = [len(str('%1.8f'% loc).split('.')[1].rstrip('0')) \\r
+ for loc in locs]\r
+ sigfigs.sort()\r
+ decimals = sigfigs[-1]\r
+ else:\r
+ decimals = self._decimals\r
+ self.format = '%1.' + str(decimals) + 'f'\r
+ if self._usetex:\r
+ self.format = '$%s$' % self.format\r
+ elif self._useMathText:\r
+ self.format = '$\mathdefault{%s}$' % self.format\r
+\r
+\r
class PlotPanel (Panel, wx.Panel):\r
"""UI for graphical curve display.\r
"""\r
d = int(config['plot decimals']) # TODO: config should convert\r
x_n, x_unit = split_data_label(x_name)\r
y_n, y_unit = split_data_label(y_name)\r
- fx = HookeFormatter(decimals=d, unit=x_unit)\r
+ fx = HookeFormatter(decimals=d)#, unit=x_unit)\r
axes.xaxis.set_major_formatter(fx)\r
fy = HookeFormatter(decimals=d, unit=y_unit)\r
axes.yaxis.set_major_formatter(fy)\r