Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* When coordinates have no well defined plot axis, iris.plot and iris.quickplot routines now use the order of the cube's dimensions to determine the coordinates to plot as the x and y axis of a plot.
8 changes: 6 additions & 2 deletions lib/iris/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,15 @@ def guess_axis(coord):
coords[axes.index(axis)] = coord

# Re-order the coordinates to achieve the preferred
# horizontal/vertical associations.
# horizontal/vertical associations. If we can't associate
# an axis to order the coordinates, fall back to using the cube dimension
# followed by the name of the coordinate.
def sort_key(coord):
order = {'X': 2, 'T': 1, 'Y': -1, 'Z': -2}
axis = guess_axis(coord)
return (order.get(axis, 0), coord and coord.name())
return (order.get(axis, 0),
coords.index(coord),
coord and coord.name())
sorted_coords = sorted(coords, key=sort_key)

transpose = (sorted_coords != coords)
Expand Down
2 changes: 1 addition & 1 deletion lib/iris/tests/test_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def setUp(self):
self.cube = cube

def test_simple(self):
iplt.contourf(self.cube)
iplt.contourf(self.cube, coords=['y', 'x'])
self.check_graphic()


Expand Down
50 changes: 50 additions & 0 deletions lib/iris/tests/unit/plot/test__get_plot_defn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# (C) British Crown Copyright 2017, Met Office
#
# This file is part of Iris.
#
# Iris is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Iris is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Iris. If not, see <http://www.gnu.org/licenses/>.
"""Unit tests for the `iris.plot._get_plot_defn` function."""

from __future__ import (absolute_import, division, print_function)
from six.moves import (filter, input, map, range, zip) # noqa

# Import iris.tests first so that some things can be initialised before
# importing anything else.
import iris.tests as tests

import iris.coords
from iris.tests.stock import simple_2d

if tests.MPL_AVAILABLE:
import iris.plot as iplt


@tests.skip_plot
class Test_get_plot_defn(tests.IrisTest):
def test_axis_order_xy(self):
cube_xy = simple_2d()
defn = iplt._get_plot_defn(cube_xy, iris.coords.POINT_MODE)
self.assertEqual([coord.name() for coord in defn.coords],
['bar', 'foo'])

def test_axis_order_yx(self):
cube_yx = simple_2d()
cube_yx.transpose()
defn = iplt._get_plot_defn(cube_yx, iris.coords.POINT_MODE)
self.assertEqual([coord.name() for coord in defn.coords],
['foo', 'bar'])


if __name__ == "__main__":
tests.main()