Repository: bokeh/bokeh

Issue:
xaxis() and yaxis() broken  in 0.5.2
Layout work related to axis locations broke these functions. This is the fix:

```
def xaxis():
    """ Get the current axis objects

    Returns:
        Returns axis object or splattable list of axis objects on the current plot
    """
    p = curplot()
    if p is None:
        return None
    axis = [obj for obj in p.above + p.below if isinstance(obj, Axis)]
    return _list_attr_splat(axis)

def yaxis():
    """ Get the current `y` axis object(s)

    Returns:
        Returns y-axis object or splattable list of y-axis objects on the current plot
    """
    p = curplot()
    if p is None:
        return None
    axis = [obj for obj in p.left + p.right if isinstance(obj, Axis)]
    return _list_attr_splat(axis)
```

xaxis() and yaxis() broken  in 0.5.2
Layout work related to axis locations broke these functions. This is the fix:

```
def xaxis():
    """ Get the current axis objects

    Returns:
        Returns axis object or splattable list of axis objects on the current plot
    """
    p = curplot()
    if p is None:
        return None
    axis = [obj for obj in p.above + p.below if isinstance(obj, Axis)]
    return _list_attr_splat(axis)

def yaxis():
    """ Get the current `y` axis object(s)

    Returns:
        Returns y-axis object or splattable list of y-axis objects on the current plot
    """
    p = curplot()
    if p is None:
        return None
    axis = [obj for obj in p.left + p.right if isinstance(obj, Axis)]
    return _list_attr_splat(axis)
```



Discussion:

Resolving patch:
diff --git a/bokeh/plotting.py b/bokeh/plotting.py
--- a/bokeh/plotting.py
+++ b/bokeh/plotting.py
@@ -583,35 +583,38 @@ def gridplot(plot_arrangement, name=None):
         save()
     return grid
 
-def xaxis():
-    """ Get the current axis objects
 
-    Returns:
-        Returns axis object or splattable list of axis objects on the current plot
-    """
+def _axis(*sides):
     p = curplot()
     if p is None:
         return None
-    axis = [obj for obj in p.renderers if isinstance(obj, Axis) and obj.location in ("top", "bottom")]
+    objs = []
+    for s in sides:
+        objs.extend(getattr(p, s, []))
+    axis = [obj for obj in objs if isinstance(obj, Axis)]
     return _list_attr_splat(axis)
 
+def xaxis():
+    """ Get the current axis objects
+
+    Returns:
+        Returns axis object or splattable list of x-axis objects on the current plot
+    """
+    return _axis("above", "below")
+
 def yaxis():
     """ Get the current `y` axis object(s)
 
     Returns:
         Returns y-axis object or splattable list of y-axis objects on the current plot
     """
-    p = curplot()
-    if p is None:
-        return None
-    axis = [obj for obj in p.renderers if isinstance(obj, Axis) and obj.location in ("left", "right")]
-    return _list_attr_splat(axis)
+    return _axis("left", "right")
 
 def axis():
     """ Get the current `x` axis object(s)
 
     Returns:
-        Returns x-axis object or splattable list of x-axis objects on the current plot
+        Returns x-axis object or splattable list of axis objects on the current plot
     """
     return _list_attr_splat(xaxis() + yaxis())
 
@@ -627,17 +630,20 @@ def legend():
     legends = [obj for obj in p.renderers if isinstance(obj, Legend)]
     return _list_attr_splat(legends)
 
+def _grid(dimension):
+    p = curplot()
+    if p is None:
+        return None
+    grid = [obj for obj in p.renderers if isinstance(obj, Grid) and obj.dimension==dimension]
+    return _list_attr_splat(grid)
+
 def xgrid():
     """ Get the current `x` :class:`grid <bokeh.objects.Grid>` object(s)
 
     Returns:
         Returns legend object or splattable list of legend objects on the current plot
     """
-    p = curplot()
-    if p is None:
-        return None
-    grid = [obj for obj in p.renderers if isinstance(obj, Grid) and obj.dimension==0]
-    return _list_attr_splat(grid)
+    return _grid(0)
 
 def ygrid():
     """ Get the current `y` :class:`grid <bokeh.objects.Grid>` object(s)
@@ -645,11 +651,7 @@ def ygrid():
     Returns:
         Returns y-grid object or splattable list of y-grid objects on the current plot
     """
-    p = curplot()
-    if p is None:
-        return None
-    grid = [obj for obj in p.renderers if isinstance(obj, Grid) and obj.dimension==1]
-    return _list_attr_splat(grid)
+    return _grid(1)
 
 def grid():
     """ Get the current :class:`grid <bokeh.objects.Grid>` object(s)
diff --git a/sphinx/source/tutorial/solutions/les_mis.py b/sphinx/source/tutorial/solutions/les_mis.py
--- a/sphinx/source/tutorial/solutions/les_mis.py
+++ b/sphinx/source/tutorial/solutions/les_mis.py
@@ -66,6 +66,7 @@
 # data. Experiment with the widths and heights (use categorical percentage
 # unite) as well as colors and alphas. Add hover and resize tools.
 rect('xname', 'yname', 0.9, 0.9, source=source,
+     x_axis_location="above",
      x_range=list(reversed(names)), y_range=names,
      color='colors', alpha='alphas', line_color=None,
      tools="resize,hover", title="Les Mis Occurrences (one at a time)",
@@ -81,7 +82,6 @@
 axis().major_tick_line_color = None
 axis().major_label_text_font_size = "5pt"
 axis().major_label_standoff = 0
-xaxis().location = "top"
 xaxis().major_label_orientation = np.pi/3
 
 # EXERCISE configure the  hover tool to display both names as well as
diff --git a/sphinx/source/tutorial/solutions/unemployment.py b/sphinx/source/tutorial/solutions/unemployment.py
--- a/sphinx/source/tutorial/solutions/unemployment.py
+++ b/sphinx/source/tutorial/solutions/unemployment.py
@@ -54,6 +54,7 @@
 #   - tools are resize and hover tools
 #   - add a nice title, and set the plot_width and plot_height
 rect('year', 'month', 0.95, 0.95, source=source,
+     x_axis_location="above",
      x_range=years, y_range=list(reversed(months)),
      color='color', line_color=None,
      tools="resize,hover", title="US Unemployment (1948 - 2013)",
@@ -69,7 +70,6 @@
 axis().major_tick_line_color = None
 axis().major_label_text_font_size = "5pt"
 axis().major_label_standoff = 0
-xaxis().location = "top"
 xaxis().major_label_orientation = np.pi/3
 
 # EXERCISE: configure the  hover tool to display the month, year and rate
@@ -79,4 +79,4 @@
     ('rate', '@rate'),
 ])
 
-show()      # show the plot
\ No newline at end of file
+show()      # show the plot


Test patch:
diff --git a/bokeh/tests/test_plotting.py b/bokeh/tests/test_plotting.py
--- a/bokeh/tests/test_plotting.py
+++ b/bokeh/tests/test_plotting.py
@@ -1,18 +1,118 @@
 import unittest
 
-import bokeh.plotting as plotting
+import bokeh.plotting as plt
+from bokeh.objects import Grid, LinearAxis
 
 class TestPlotting(unittest.TestCase):
 
     def test_reset_output(self):
-        plotting._default_document = 10
-        plotting._default_session = 10
-        plotting._default_file = 10
-        plotting._default_notebook = 10
-        plotting.reset_output()
-        self.assertTrue(isinstance(plotting._default_document, plotting.Document))
-        self.assertEqual(plotting._default_session, None)
-        self.assertEqual(plotting._default_file, None)
-        self.assertEqual(plotting._default_notebook, None)
+        plt._default_document = 10
+        plt._default_session = 10
+        plt._default_file = 10
+        plt._default_notebook = 10
+        plt.reset_output()
+        self.assertTrue(isinstance(plt._default_document, plt.Document))
+        self.assertEqual(plt._default_session, None)
+        self.assertEqual(plt._default_file, None)
+        self.assertEqual(plt._default_notebook, None)
+
+    def test_figure(self):
+        plt.figure()
+        self.assertEqual(plt.curplot(), None)
+        p = plt.circle([1,2,3], [1,2,3])
+        self.assertEqual(plt.curplot(), p)
+        plt.figure()
+        self.assertEqual(plt.curplot(), None)
+
+    def test_xaxis(self):
+        plt.figure()
+        p = plt.circle([1,2,3], [1,2,3])
+        self.assertEqual(len(plt.xaxis()), 1)
+
+        expected = set(plt.xaxis())
+
+        ax = LinearAxis()
+        expected.add(ax)
+        p.above.append(ax)
+        self.assertEqual(set(plt.xaxis()), expected)
+
+        ax2 = LinearAxis()
+        expected.add(ax2)
+        p.above.append(ax2)
+        self.assertEqual(set(plt.xaxis()), expected)
+
+        p.left.append(LinearAxis())
+        self.assertEqual(set(plt.xaxis()), expected)
+
+        p.right.append(LinearAxis())
+        self.assertEqual(set(plt.xaxis()), expected)
+
+    def test_yaxis(self):
+        plt.figure()
+        p = plt.circle([1,2,3], [1,2,3])
+        self.assertEqual(len(plt.yaxis()), 1)
+
+        expected = set(plt.yaxis())
+
+        ax = LinearAxis()
+        expected.add(ax)
+        p.right.append(ax)
+        self.assertEqual(set(plt.yaxis()), expected)
+
+        ax2 = LinearAxis()
+        expected.add(ax2)
+        p.right.append(ax2)
+        self.assertEqual(set(plt.yaxis()), expected)
+
+        p.above.append(LinearAxis())
+        self.assertEqual(set(plt.yaxis()), expected)
+
+        p.below.append(LinearAxis())
+        self.assertEqual(set(plt.yaxis()), expected)
+
+    def test_axis(self):
+        plt.figure()
+        p = plt.circle([1,2,3], [1,2,3])
+        self.assertEqual(len(plt.axis()), 2)
+
+        expected = set(plt.axis())
+
+        ax = LinearAxis()
+        expected.add(ax)
+        p.above.append(ax)
+        self.assertEqual(set(plt.axis()), expected)
+
+        ax2 = LinearAxis()
+        expected.add(ax2)
+        p.below.append(ax2)
+        self.assertEqual(set(plt.axis()), expected)
+
+        ax3 = LinearAxis()
+        expected.add(ax3)
+        p.left.append(ax3)
+        self.assertEqual(set(plt.axis()), expected)
+
+        ax4 = LinearAxis()
+        expected.add(ax4)
+        p.right.append(ax4)
+        self.assertEqual(set(plt.axis()), expected)
+
+    def test_xgrid(self):
+        plt.figure()
+        p = plt.circle([1,2,3], [1,2,3])
+        self.assertEqual(len(plt.xgrid()), 1)
+        self.assertEqual(plt.xgrid()[0].dimension, 0)
+
+    def test_ygrid(self):
+        plt.figure()
+        p = plt.circle([1,2,3], [1,2,3])
+        self.assertEqual(len(plt.ygrid()), 1)
+        self.assertEqual(plt.ygrid()[0].dimension, 1)
+
+    def test_grid(self):
+        plt.figure()
+        p = plt.circle([1,2,3], [1,2,3])
+        self.assertEqual(len(plt.grid()), 2)
+