diff --git a/lib/matplotlib/tests/baseline_images/test_axes/log_scales.pdf b/lib/matplotlib/tests/baseline_images/test_axes/log_scales.pdf new file mode 100644 index 000000000000..91ca540b6719 Binary files /dev/null and b/lib/matplotlib/tests/baseline_images/test_axes/log_scales.pdf differ diff --git a/lib/matplotlib/tests/baseline_images/test_axes/log_scales.png b/lib/matplotlib/tests/baseline_images/test_axes/log_scales.png new file mode 100644 index 000000000000..a925af6aa4ea Binary files /dev/null and b/lib/matplotlib/tests/baseline_images/test_axes/log_scales.png differ diff --git a/lib/matplotlib/tests/baseline_images/test_axes/log_scales.svg b/lib/matplotlib/tests/baseline_images/test_axes/log_scales.svg new file mode 100644 index 000000000000..7d4687efc1dd --- /dev/null +++ b/lib/matplotlib/tests/baseline_images/test_axes/log_scales.svg @@ -0,0 +1,670 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index d32cf66b2aea..1b80e3a26930 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -762,6 +762,14 @@ def _as_mpl_axes(self): 'Expected a PolarAxesSubplot, got %s' % type(ax) plt.close() +@image_comparison(baseline_images=['log_scales']) +def test_log_scales(): + fig = plt.figure() + ax = plt.gca() + plt.plot(np.log(np.linspace(0.1, 100))) + ax.set_yscale('log', basey=5.5) + ax.set_xscale('log', basex=9.0) + if __name__=='__main__': import nose diff --git a/lib/matplotlib/ticker.py b/lib/matplotlib/ticker.py index 12134556e572..57176c89ad23 100644 --- a/lib/matplotlib/ticker.py +++ b/lib/matplotlib/ticker.py @@ -567,9 +567,8 @@ class LogFormatter(Formatter): """ Format values for log axis; - if attribute *decadeOnly* is True, only the decades will be labelled. """ - def __init__(self, base=10.0, labelOnlyBase = True): + def __init__(self, base=10.0, labelOnlyBase=True): """ *base* is used to locate the decade tick, which will be the only one to be labeled if *labelOnlyBase* @@ -577,17 +576,15 @@ def __init__(self, base=10.0, labelOnlyBase = True): """ self._base = base+0.0 self.labelOnlyBase = labelOnlyBase - self.decadeOnly = True - + def base(self, base): 'change the *base* for labeling - warning: should always match the base used for :class:`LogLocator`' self._base = base - + def label_minor(self, labelOnlyBase): 'switch on/off minor ticks labeling' self.labelOnlyBase = labelOnlyBase - def __call__(self, x, pos=None): 'Return the format for tick val *x* at position *pos*' vmin, vmax = self.axis.get_view_interval() @@ -650,7 +647,6 @@ class LogFormatterExponent(LogFormatter): def __call__(self, x, pos=None): 'Return the format for tick val *x* at position *pos*' - vmin, vmax = self.axis.get_view_interval() vmin, vmax = mtransforms.nonsingular(vmin, vmax, expander = 0.05) d = abs(vmax-vmin) @@ -690,29 +686,35 @@ def __call__(self, x, pos=None): return '$0$' else: return '$\mathdefault{0}$' - sign = np.sign(x) - fx = math.log(abs(x))/math.log(b) - isDecade = is_close_to_int(fx) - - if sign == -1: - sign_string = '-' + + fx = math.log(abs(x)) / math.log(b) + is_decade = is_close_to_int(fx) + + sign_string = '-' if x < 0 else '' + + # use string formatting of the base if it is not an integer + if b % 1 == 0.0: + base = '%d' % b else: - sign_string = '' + base = '%s' % b - if not isDecade and self.labelOnlyBase: s = '' - elif not isDecade: + if not is_decade and self.labelOnlyBase: + return '' + elif not is_decade: if usetex: - s = r'$%s%d^{%.2f}$'% (sign_string, b, fx) + return (r'$%s%s^{%.2f}$') % \ + (sign_string, base, fx) else: - s = '$\mathdefault{%s%d^{%.2f}}$'% (sign_string, b, fx) + return ('$\mathdefault{%s%s^{%.2f}}$') % \ + (sign_string, base, fx) else: if usetex: - s = r'$%s%d^{%d}$'% (sign_string, b, nearest_long(fx)) + return (r'$%s%s^{%d}$') % \ + (sign_string, base, nearest_long(fx)) else: - s = r'$\mathdefault{%s%d^{%d}}$'% (sign_string, b, - nearest_long(fx)) + return (r'$\mathdefault{%s%s^{%d}}$') % \ + (sign_string, base, nearest_long(fx)) - return s class EngFormatter(Formatter): """