Skip to content
Closed
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 @@
* iris.plot.plot an iris.quickplot.plot now automatically place the cube on the x axis if the primary coordinate being plotted against is a vertical coordinate. (e.g. ``iris.plot.plot(z_cube)`` would produce an z vs phenomenon plot, where before it would have produced a phenomenon vs z one)
14 changes: 13 additions & 1 deletion lib/iris/plot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# (C) British Crown Copyright 2010 - 2017, Met Office
# (C) British Crown Copyright 2010 - 2018, Met Office
#
# This file is part of Iris.
#
Expand Down Expand Up @@ -483,7 +483,19 @@ def _get_plot_objects(args):
# single argument
v_object = args[0]
u_object = _u_object_from_v_object(v_object)

u, v = _uv_from_u_object_v_object(u_object, args[0])

# If a single cube argument, and the associated dimension coordinate
# is vertical-like, put the coordinate on the y axis, and the data o
# the x.
if (isinstance(v_object, iris.cube.Cube) and
iris.util.guess_coord_axis(u_object) in ['Y', 'Z']):
# If we have a single argument, and it is vertial-like, put it on
# the y axis.
u_object, v_object = v_object, u_object
u, v = v, u

args = args[1:]
return u_object, v_object, u, v, args

Expand Down
9 changes: 3 additions & 6 deletions lib/iris/quickplot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# (C) British Crown Copyright 2010 - 2016, Met Office
# (C) British Crown Copyright 2010 - 2018, Met Office
#
# This file is part of Iris.
#
Expand Down Expand Up @@ -127,11 +127,8 @@ def _get_titles(u_object, v_object):


def _label_1d_plot(*args):
if len(args) > 1 and isinstance(args[1],
(iris.cube.Cube, iris.coords.Coord)):
xlabel, ylabel, title = _get_titles(*args[:2])
else:
xlabel, ylabel, title = _get_titles(None, args[0])
u_obj, v_obj, _, _, _ = iplt._get_plot_objects(args)
xlabel, ylabel, title = _get_titles(u_obj, v_obj)
plt.title(title)
plt.xlabel(xlabel)
plt.ylabel(ylabel)
Expand Down
2 changes: 1 addition & 1 deletion lib/iris/tests/idiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def step_over_diffs(result_dir, action, display=True):
if isinstance(e, ValueError) or \
isinstance(e, ImageComparisonFailure):
print('Could not compare {}: {}'.format(result_fname,
e.message))
str(e)))
continue
else:
# Propagate the exception, keeping the stack trace
Expand Down
26 changes: 25 additions & 1 deletion lib/iris/tests/unit/quickplot/test_plot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# (C) British Crown Copyright 2014 - 2015, Met Office
# (C) British Crown Copyright 2014 - 2018, Met Office
#
# This file is part of Iris.
#
Expand All @@ -22,6 +22,7 @@
# Import iris.tests first so that some things can be initialised before
# importing anything else.
import iris.tests as tests
from iris.tests.stock import simple_2d
from iris.tests.unit.plot import TestGraphicStringCoord

if tests.MPL_AVAILABLE:
Expand All @@ -43,5 +44,28 @@ def test_xaxis_labels(self):
self.assertPointsTickLabels('xaxis')


class TestAxisLabels(tests.GraphicsTest):
def test_xy_cube(self):
c = simple_2d()[:, 0]
qplt.plot(c)
ax = qplt.plt.gca()
x = ax.xaxis.get_label().get_text()
self.assertEqual(x, 'Bar')
y = ax.yaxis.get_label().get_text()
self.assertEqual(y, 'Thingness')

def test_yx_cube(self):
c = simple_2d()[:, 0]
c.transpose()
# Making the cube a vertical coordinate should change the default
# orientation of the plot.
c.coord('bar').attributes['positive'] = 'up'
qplt.plot(c)
ax = qplt.plt.gca()
x = ax.xaxis.get_label().get_text()
self.assertEqual(x, 'Thingness')
y = ax.yaxis.get_label().get_text()
self.assertEqual(y, 'Bar')

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