Skip to content

Commit f056044

Browse files
committed
Set 1D plots to put the coordinate on the y-axis where appropriate.
1 parent 077df3e commit f056044

File tree

3 files changed

+40
-6
lines changed

3 files changed

+40
-6
lines changed

lib/iris/plot.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,20 @@ def _get_plot_objects(args):
665665
# single argument
666666
v_object = args[0]
667667
u_object = _u_object_from_v_object(v_object)
668+
668669
u, v = _uv_from_u_object_v_object(u_object, args[0])
670+
671+
# If a single cube argument, and the associated dimension coordinate
672+
# is vertical-like, put the coordinate on the y axis, and the data o
673+
# the x.
674+
if isinstance(v_object, iris.cube.Cube) and iris.util.guess_coord_axis(
675+
u_object
676+
) in ["Y", "Z"]:
677+
# If we have a single argument, and it is vertical-like, put it on
678+
# the y axis.
679+
u_object, v_object = v_object, u_object
680+
u, v = v, u
681+
669682
args = args[1:]
670683
return u_object, v_object, u, v, args
671684

lib/iris/quickplot.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,8 @@ def _get_titles(u_object, v_object):
138138

139139

140140
def _label_1d_plot(*args, **kwargs):
141-
if len(args) > 1 and isinstance(
142-
args[1], (iris.cube.Cube, iris.coords.Coord)
143-
):
144-
xlabel, ylabel, title = _get_titles(*args[:2])
145-
else:
146-
xlabel, ylabel, title = _get_titles(None, args[0])
141+
u_obj, v_obj, _, _, _ = iplt._get_plot_objects(args)
142+
xlabel, ylabel, title = _get_titles(u_obj, v_obj)
147143

148144
axes = kwargs.pop("axes", None)
149145

lib/iris/tests/unit/quickplot/test_plot.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
# Import iris.tests first so that some things can be initialised before
99
# importing anything else.
1010
import iris.tests as tests
11+
from iris.tests.stock import simple_2d
1112
from iris.tests.unit.plot import TestGraphicStringCoord
1213

1314
if tests.MPL_AVAILABLE:
@@ -29,5 +30,29 @@ def test_xaxis_labels(self):
2930
self.assertBoundsTickLabels("xaxis")
3031

3132

33+
class TestAxisLabels(tests.GraphicsTest):
34+
def test_xy_cube(self):
35+
c = simple_2d()[:, 0]
36+
qplt.plot(c)
37+
ax = qplt.plt.gca()
38+
x = ax.xaxis.get_label().get_text()
39+
self.assertEqual(x, "Bar")
40+
y = ax.yaxis.get_label().get_text()
41+
self.assertEqual(y, "Thingness")
42+
43+
def test_yx_cube(self):
44+
c = simple_2d()[:, 0]
45+
c.transpose()
46+
# Making the cube a vertical coordinate should change the default
47+
# orientation of the plot.
48+
c.coord("bar").attributes["positive"] = "up"
49+
qplt.plot(c)
50+
ax = qplt.plt.gca()
51+
x = ax.xaxis.get_label().get_text()
52+
self.assertEqual(x, "Thingness")
53+
y = ax.yaxis.get_label().get_text()
54+
self.assertEqual(y, "Bar")
55+
56+
3257
if __name__ == "__main__":
3358
tests.main()

0 commit comments

Comments
 (0)