Repository: pandas-dev/pandas

Issue:
DataFrame.hist does not honor sharex or sharey set to True
[Here is an example](http://nbviewer.ipython.org/urls/gist.github.com/fonnesbeck/5897459/raw/6181f066f245c7fb489b68f88e4b4731c77a238b/King%27s+Bay+Survey+Analysis.ipynb) of the `hist` method called as a multi-panel plot via the `by` argument, with `sharey=True` and `sharex=True`. As you can observe in the plot at the bottom of the notebook, neither the x nor the y axis is shared among the subplots.

Running 0.11.1 on Python 2.7.2 (OS X 10.8.4).



Discussion:
so the issue is that using `by` doesn't pass the `share*` params. i'll see what i can do

@fonnesbeck thanks. pr coming


Resolving patch:
diff --git a/pandas/tools/plotting.py b/pandas/tools/plotting.py
--- a/pandas/tools/plotting.py
+++ b/pandas/tools/plotting.py
@@ -1928,7 +1928,7 @@ def hist_frame(data, column=None, by=None, grid=True, xlabelsize=None,
     if by is not None:
 
         axes = grouped_hist(data, by=by, ax=ax, grid=grid, figsize=figsize,
-                            **kwds)
+                            sharex=sharex, sharey=sharey, **kwds)
 
         for ax in axes.ravel():
             if xlabelsize is not None:


Test patch:
diff --git a/pandas/tests/test_graphics.py b/pandas/tests/test_graphics.py
--- a/pandas/tests/test_graphics.py
+++ b/pandas/tests/test_graphics.py
@@ -12,6 +12,7 @@
 
 
 import numpy as np
+from numpy import random
 
 from numpy.testing import assert_array_equal
 from numpy.testing.decorators import slow
@@ -947,6 +948,38 @@ def test_grouped_hist(self):
         self.assertRaises(AttributeError, plotting.grouped_hist, df.A,
                           by=df.C, foo='bar')
 
+    @slow
+    def test_axis_shared(self):
+        # GH4089
+        import matplotlib.pyplot as plt
+        def tick_text(tl):
+            return [x.get_text() for x in tl]
+
+        n = 100
+        df = DataFrame({'gender': np.array(['Male', 'Female'])[random.randint(2, size=n)],
+                        'height': random.normal(66, 4, size=n),
+                        'weight': random.normal(161, 32, size=n)})
+        ax1, ax2 = df.hist(column='height', by=df.gender, sharex=True)
+        self.assert_(ax1._shared_x_axes.joined(ax1, ax2))
+        self.assertFalse(ax1._shared_y_axes.joined(ax1, ax2))
+        self.assert_(ax2._shared_x_axes.joined(ax1, ax2))
+        self.assertFalse(ax2._shared_y_axes.joined(ax1, ax2))
+        plt.close('all')
+
+        ax1, ax2 = df.hist(column='height', by=df.gender, sharey=True)
+        self.assertFalse(ax1._shared_x_axes.joined(ax1, ax2))
+        self.assert_(ax1._shared_y_axes.joined(ax1, ax2))
+        self.assertFalse(ax2._shared_x_axes.joined(ax1, ax2))
+        self.assert_(ax2._shared_y_axes.joined(ax1, ax2))
+        plt.close('all')
+
+        ax1, ax2 = df.hist(column='height', by=df.gender, sharex=True,
+                           sharey=True)
+        self.assert_(ax1._shared_x_axes.joined(ax1, ax2))
+        self.assert_(ax1._shared_y_axes.joined(ax1, ax2))
+        self.assert_(ax2._shared_x_axes.joined(ax1, ax2))
+        self.assert_(ax2._shared_y_axes.joined(ax1, ax2))
+
     def test_option_mpl_style(self):
         set_option('display.mpl_style', 'default')
         set_option('display.mpl_style', None)