Repository: pandas-dev/pandas

Issue:
unexpected axis ticks in tools.plotting.scatter_matrix
The upper left y axis tick marks in a scatter_matrix appear to have units/values pulled from the (0, 0) histogram counts, instead of the data values that are used for all other axis tick values.

Example:

```
In [1]: import numpy as np

In [2]: import pandas as pd

In [3]: pd.__version__
Out[3]: '0.12.0'

In [4]: df = pd.DataFrame(np.random.randn(100,3), columns=['a', 'b', 'c'])

In [5]: pd.tools.plotting.scatter_matrix(df)
Out[5]: 
array([[<matplotlib.axes.AxesSubplot object at 0x1071d5d90>,
        <matplotlib.axes.AxesSubplot object at 0x1089aa0d0>,
        <matplotlib.axes.AxesSubplot object at 0x1071e36d0>],
       [<matplotlib.axes.AxesSubplot object at 0x10a7d4f90>,
        <matplotlib.axes.AxesSubplot object at 0x10a7fd450>,
        <matplotlib.axes.AxesSubplot object at 0x10a8197d0>],
       [<matplotlib.axes.AxesSubplot object at 0x10a83bf90>,
        <matplotlib.axes.AxesSubplot object at 0x10a84fe50>,
        <matplotlib.axes.AxesSubplot object at 0x10a886310>]], dtype=object)
```

![figure_1](https://f.cloud.github.com/assets/6042395/1699217/0ceb08aa-5f89-11e3-9cf2-0b6f4fed6fee.png)



Discussion:

Resolving patch:
diff --git a/pandas/tools/plotting.py b/pandas/tools/plotting.py
--- a/pandas/tools/plotting.py
+++ b/pandas/tools/plotting.py
@@ -303,45 +303,32 @@ def scatter_matrix(frame, alpha=0.5, figsize=None, ax=None, grid=False,
                 ax.set_xlim(boundaries_list[j])
                 ax.set_ylim(boundaries_list[i])
 
-            ax.set_xlabel('')
-            ax.set_ylabel('')
-
-            _label_axis(ax, kind='x', label=b, position='bottom', rotate=True)
-
-            _label_axis(ax, kind='y', label=a, position='left')
+            ax.set_xlabel(b)
+            ax.set_ylabel(a)
 
             if j!= 0:
                 ax.yaxis.set_visible(False)
             if i != n-1:
                 ax.xaxis.set_visible(False)
 
-    for ax in axes.flat:
-        setp(ax.get_xticklabels(), fontsize=8)
-        setp(ax.get_yticklabels(), fontsize=8)
+    if len(df.columns) > 1:
+        lim1 = boundaries_list[0]
+        locs = axes[0][1].yaxis.get_majorticklocs()
+        locs = locs[(lim1[0] <= locs) & (locs <= lim1[1])]
+        adj = (locs - lim1[0]) / (lim1[1] - lim1[0])
 
-    return axes
-
-def _label_axis(ax, kind='x', label='', position='top',
-    ticks=True, rotate=False):
-
-    from matplotlib.artist import setp
-    if kind == 'x':
-        ax.set_xlabel(label, visible=True)
-        ax.xaxis.set_visible(True)
-        ax.xaxis.set_ticks_position(position)
-        ax.xaxis.set_label_position(position)
-        if rotate:
-            setp(ax.get_xticklabels(), rotation=90)
-    elif kind == 'y':
-        ax.yaxis.set_visible(True)
-        ax.set_ylabel(label, visible=True)
-        # ax.set_ylabel(a)
-        ax.yaxis.set_ticks_position(position)
-        ax.yaxis.set_label_position(position)
-    return
+        lim0 = axes[0][0].get_ylim()
+        adj = adj * (lim0[1] - lim0[0]) + lim0[0]
+        axes[0][0].yaxis.set_ticks(adj)
 
+        if np.all(locs == locs.astype(int)):
+            # if all ticks are int
+            locs = locs.astype(int)
+        axes[0][0].yaxis.set_ticklabels(locs)
 
+    _set_ticks_props(axes, xlabelsize=8, xrot=90, ylabelsize=8, yrot=0)
 
+    return axes
 
 
 def _gca():


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
@@ -2353,10 +2353,9 @@ def test_scatter(self):
         tm._skip_if_no_scipy()
 
         df = DataFrame(randn(100, 2))
-        import pandas.tools.plotting as plt
 
         def scat(**kwds):
-            return plt.scatter_matrix(df, **kwds)
+            return plotting.scatter_matrix(df, **kwds)
 
         _check_plot_works(scat)
         _check_plot_works(scat, marker='+')
@@ -2369,12 +2368,33 @@ def scat(**kwds):
         _check_plot_works(scat, range_padding=.1)
 
         def scat2(x, y, by=None, ax=None, figsize=None):
-            return plt.scatter_plot(df, x, y, by, ax, figsize=None)
+            return plotting.scatter_plot(df, x, y, by, ax, figsize=None)
 
         _check_plot_works(scat2, 0, 1)
         grouper = Series(np.repeat([1, 2, 3, 4, 5], 20), df.index)
         _check_plot_works(scat2, 0, 1, by=grouper)
 
+    def test_scatter_matrix_axis(self):
+        tm._skip_if_no_scipy()
+        scatter_matrix = plotting.scatter_matrix
+
+        with tm.RNGContext(42):
+            df = DataFrame(randn(100, 3))
+
+        axes = _check_plot_works(scatter_matrix, df, range_padding=.1)
+        axes0_labels = axes[0][0].yaxis.get_majorticklabels()
+        # GH 5662
+        expected = ['-2', '-1', '0', '1', '2']
+        self._check_text_labels(axes0_labels, expected)
+        self._check_ticks_props(axes, xlabelsize=8, xrot=90, ylabelsize=8, yrot=0)
+
+        df[0] = ((df[0] - 2) / 3)
+        axes = _check_plot_works(scatter_matrix, df, range_padding=.1)
+        axes0_labels = axes[0][0].yaxis.get_majorticklabels()
+        expected = ['-1.2', '-1.0', '-0.8', '-0.6', '-0.4', '-0.2', '0.0']
+        self._check_text_labels(axes0_labels, expected)
+        self._check_ticks_props(axes, xlabelsize=8, xrot=90, ylabelsize=8, yrot=0)
+
     @slow
     def test_andrews_curves(self):
         from pandas.tools.plotting import andrews_curves