diff --git a/doc/source/whatsnew/v0.16.1.txt b/doc/source/whatsnew/v0.16.1.txt index 090ef9ea92fc1..1c8c207e0955a 100644 --- a/doc/source/whatsnew/v0.16.1.txt +++ b/doc/source/whatsnew/v0.16.1.txt @@ -144,8 +144,8 @@ Bug Fixes - Bug in ``MultiIndex.sortlevel()`` results in unicode level name breaks (:issue:`9875`) - Bug in which ``groupby.transform`` incorrectly enforced output dtypes to match input dtypes. (:issue:`9807`) - - +- Bug in bar plot with ``log=True`` raises ``TypeError`` if all values are less than 1 (:issue:`9905`) +- Bug in horizontal bar plot ignores ``log=True`` (:issue:`9905`) diff --git a/pandas/tests/test_graphics.py b/pandas/tests/test_graphics.py index a90fbe6c25b1f..7ec57c0304530 100644 --- a/pandas/tests/test_graphics.py +++ b/pandas/tests/test_graphics.py @@ -592,6 +592,26 @@ def test_bar_log(self): ax = Series([200, 500]).plot(log=True, kind='bar') assert_array_equal(ax.yaxis.get_ticklocs(), expected) + tm.close() + + ax = Series([200, 500]).plot(log=True, kind='barh') + assert_array_equal(ax.xaxis.get_ticklocs(), expected) + tm.close() + + # GH 9905 + expected = np.array([1.0e-03, 1.0e-02, 1.0e-01, 1.0e+00]) + + if not self.mpl_le_1_2_1: + expected = np.hstack((1.0e-04, expected, 1.0e+01)) + + ax = Series([0.1, 0.01, 0.001]).plot(log=True, kind='bar') + assert_array_equal(ax.get_ylim(), (0.001, 0.10000000000000001)) + assert_array_equal(ax.yaxis.get_ticklocs(), expected) + tm.close() + + ax = Series([0.1, 0.01, 0.001]).plot(log=True, kind='barh') + assert_array_equal(ax.get_xlim(), (0.001, 0.10000000000000001)) + assert_array_equal(ax.xaxis.get_ticklocs(), expected) @slow def test_bar_ignore_index(self): diff --git a/pandas/tools/plotting.py b/pandas/tools/plotting.py index fe4751b1dc0a4..513f165af4686 100644 --- a/pandas/tools/plotting.py +++ b/pandas/tools/plotting.py @@ -1824,11 +1824,12 @@ def _get_plot_function(self): if self.kind == 'bar': def f(ax, x, y, w, start=None, **kwds): start = start + self.bottom - return ax.bar(x, y, w, bottom=start,log=self.log, **kwds) + return ax.bar(x, y, w, bottom=start, log=self.log, **kwds) elif self.kind == 'barh': + def f(ax, x, y, w, start=None, log=self.log, **kwds): start = start + self.left - return ax.barh(x, y, w, left=start, **kwds) + return ax.barh(x, y, w, left=start, log=self.log, **kwds) else: raise ValueError("BarPlot kind must be either 'bar' or 'barh'") @@ -1836,9 +1837,6 @@ def f(ax, x, y, w, start=None, log=self.log, **kwds): def _make_plot(self): import matplotlib as mpl - # mpl decided to make their version string unicode across all Python - # versions for mpl >= 1.3 so we have to call str here for python 2 - mpl_le_1_2_1 = str(mpl.__version__) <= LooseVersion('1.2.1') colors = self._get_colors() ncolors = len(colors) @@ -1862,11 +1860,8 @@ def _make_plot(self): kwds['ecolor'] = mpl.rcParams['xtick.color'] start = 0 - if self.log: + if self.log and (y >= 1).all(): start = 1 - if any(y < 1): - # GH3254 - start = 0 if mpl_le_1_2_1 else None if self.subplots: w = self.bar_width / 2