Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

More sensible time axis and tick labels for 2D plots #5561

Merged
merged 6 commits into from
Nov 3, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/benchmarks_run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
env:
IRIS_TEST_DATA_LOC_PATH: benchmarks
IRIS_TEST_DATA_PATH: benchmarks/iris-test-data
IRIS_TEST_DATA_VERSION: "2.21"
IRIS_TEST_DATA_VERSION: "2.22"
# Lets us manually bump the cache to rebuild
ENV_CACHE_BUILD: "0"
TEST_DATA_CACHE_BUILD: "2"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
session: "tests"

env:
IRIS_TEST_DATA_VERSION: "2.21"
IRIS_TEST_DATA_VERSION: "2.22"
ENV_NAME: "ci-tests"

steps:
Expand Down
3 changes: 3 additions & 0 deletions docs/src/whatsnew/latest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ This document explains the changes made to Iris for this release
#. `@ESadek-MO`_ has updated :mod:`iris.tests.graphics.idiff` to stop duplicated file names
preventing acceptance. (:issue:`5098`, :pull:`5482`)

#. `@acchamber`_ and `@rcomer`_ modified 2D plots so that time axes and their
ticks have more sensible default labels. (:issue:`5426`, :pull:`5561`)


馃挘 Incompatible Changes
=======================
Expand Down
9 changes: 0 additions & 9 deletions lib/iris/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import matplotlib.animation as animation
import matplotlib.axes
import matplotlib.collections as mpl_collections
import matplotlib.dates as mpl_dates
from matplotlib.offsetbox import AnchoredText
import matplotlib.pyplot as plt
import matplotlib.ticker as mpl_ticker
Expand Down Expand Up @@ -454,10 +453,6 @@ def _draw_2d_from_bounds(draw_method_name, cube, *args, **kwargs):
else:
values = coord.contiguous_bounds()
values = _fixup_dates(coord, values)
if values.dtype == np.dtype(object) and isinstance(
values[0], datetime.datetime
):
values = mpl_dates.date2num(values)
trexfeathers marked this conversation as resolved.
Show resolved Hide resolved

plot_arrays.append(values)

Expand Down Expand Up @@ -557,10 +552,6 @@ def _draw_2d_from_points(draw_method_name, arg_func, cube, *args, **kwargs):
)
plot_arrays.append(np.arange(values.size))
string_axes[axis_name] = values
elif values.dtype == np.dtype(object) and isinstance(
values[0], datetime.datetime
):
plot_arrays.append(mpl_dates.date2num(values))
trexfeathers marked this conversation as resolved.
Show resolved Hide resolved
else:
plot_arrays.append(values)

Expand Down
17 changes: 3 additions & 14 deletions lib/iris/quickplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
"""

import cf_units
from matplotlib import __version__ as _mpl_version
import matplotlib.pyplot as plt
from packaging import version

import iris.config
import iris.coords
Expand Down Expand Up @@ -44,18 +42,11 @@ def _title(cube_or_coord, with_units):
units.is_unknown()
or units.is_no_unit()
or units == cf_units.Unit("1")
or units.is_time_reference()
):
if _use_symbol(units):
units = units.symbol
elif units.is_time_reference():
# iris.plot uses matplotlib.dates.date2num, which is fixed to the below unit.
if version.parse(_mpl_version) >= version.parse("3.3"):
days_since = "1970-01-01"
else:
days_since = "0001-01-01"
units = "days since {}".format(days_since)
title += " / {}".format(units)

return title


Expand Down Expand Up @@ -117,10 +108,8 @@ def _label_with_points(cube, result=None, ndims=2, coords=None, axes=None):
def _get_titles(u_object, v_object):
if u_object is None:
u_object = iplt._u_object_from_v_object(v_object)
xunits = u_object is not None and not u_object.units.is_time_reference()
trexfeathers marked this conversation as resolved.
Show resolved Hide resolved
yunits = not v_object.units.is_time_reference()
xlabel = _title(u_object, with_units=xunits)
ylabel = _title(v_object, with_units=yunits)
xlabel = _title(u_object, with_units=True)
ylabel = _title(v_object, with_units=True)
title = ""
if u_object is None:
title = _title(v_object, with_units=False)
Expand Down
32 changes: 16 additions & 16 deletions lib/iris/tests/results/imagerepo.json
trexfeathers marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@
"iris.tests.test_plot.TestHybridHeight.test_points.3": "fe857b91917a847ec4bd3f01c47c6ca43b11915a3ea4db3b1b4a84c4c03f3fc1",
"iris.tests.test_plot.TestHybridHeight.test_points.4": "b878387e978ec2f0c0f09f83878f3f81c070c0fe78d0c1763fa13856d03e3f0f",
"iris.tests.test_plot.TestMissingCS.test_missing_cs.0": "fa816ac1857e853cc17e957ac15f3e8494c6c8f43e81c13b3f813e91c07e3f46",
"iris.tests.test_plot.TestMissingCoord.test_no_u.0": "ea856a95955a954ac17f954a807e3f48951ac07e3f81c0ff7ea16a81c0bf3f81",
"iris.tests.test_plot.TestMissingCoord.test_no_u.1": "ea956ab5954a954ac17e9542817f2f60950ac07f3e80c0ff7a856aa5c2ff3f80",
"iris.tests.test_plot.TestMissingCoord.test_no_u.0": "ea856a95955a956ac17f954a817e3f8c953ac07e3e81c07f7ea16a81c07e3e81",
"iris.tests.test_plot.TestMissingCoord.test_no_u.1": "ea956ab5954a954ac17e954a857f3f80954ac07f7e80c07f7a856a84c07f3f81",
"iris.tests.test_plot.TestMissingCoord.test_no_v.0": "fa816a85957a857ac17e954ac17e1fa2950bc07e3e81c07f3e807a85c17f3f81",
"iris.tests.test_plot.TestMissingCoord.test_no_v.1": "fa856a85957a857ac17e954ac17e9d02954ac07e3e81c07f3e857a85c2fd3f80",
"iris.tests.test_plot.TestMissingCoord.test_none.0": "fa816a85957a857ac17e954ac17e3fa2950ac07e3e80c07f3e807a85c1ff3f81",
Expand Down Expand Up @@ -168,12 +168,12 @@
"iris.tests.test_plot.TestPlotCitation.test_axes.0": "abf895467a1d9506f811783485437abd85427ab995067ab9f00687f96afe87c8",
"iris.tests.test_plot.TestPlotCitation.test_figure.0": "abf895467a1d9506f811783485437abd85427ab995067ab9f00687f96afe87c8",
"iris.tests.test_plot.TestPlotCoordinatesGiven.test_non_cube_coordinate.0": "fa81857e857e3e85857e7a81857e7a81857e7a817e81780b7a81c56a7a81857e",
"iris.tests.test_plot.TestPlotCoordinatesGiven.test_tx.0": "ea853f10956ac1e1957a854e957a207e955e6aa76ae17aa16a856aaf6ab19e12",
"iris.tests.test_plot.TestPlotCoordinatesGiven.test_tx.1": "ea853a85857a857a957a857a957ed05a857b3e946a606b917a816f247a853af4",
"iris.tests.test_plot.TestPlotCoordinatesGiven.test_tx.2": "eafdcec9f4219530b696a56694c3852a95656b7b85986acdc06516adad186e9a",
"iris.tests.test_plot.TestPlotCoordinatesGiven.test_tx.3": "aff24ab7fd05952dbd0f950f910fed48c47868f2e1b9329094266e345a850f6c",
"iris.tests.test_plot.TestPlotCoordinatesGiven.test_tx.4": "eaa9b5699556854e9456854ed05625f9d0a92bfdc0a90afd81f97e00855e7ab6",
"iris.tests.test_plot.TestPlotCoordinatesGiven.test_tx.5": "eaf73e0d9503852c950395ac9528c1fad06cc0f2d1ec6af2c0fc6a536a1797f3",
"iris.tests.test_plot.TestPlotCoordinatesGiven.test_tx.0": "ea853e11956ac1e3957a844e957a607e955e6ae36ae17aa16a856be86ab13c32",
"iris.tests.test_plot.TestPlotCoordinatesGiven.test_tx.1": "ea857a85857ac57a957a857a957ad05e850b3ed46e206b917a816f247a953ae4",
"iris.tests.test_plot.TestPlotCoordinatesGiven.test_tx.2": "ebfdcac9bd209434b696856795cb012e95676b7b81186acdc06536ad89182fda",
"iris.tests.test_plot.TestPlotCoordinatesGiven.test_tx.3": "aaff7ab2fd04902cfd0c950f9d010f4bd64069f3e1993a9894262e345ae56f6c",
"iris.tests.test_plot.TestPlotCoordinatesGiven.test_tx.4": "eaa9d5129556c55695568556955623f9c0292bf9c0a90bfdc0fd7e0085562ff9",
"iris.tests.test_plot.TestPlotCoordinatesGiven.test_tx.5": "eaf77a0d9553c52c950095ac952885ea952c87f3952c6bf3d42c6a536a57bf80",
"iris.tests.test_plot.TestPlotCoordinatesGiven.test_x.0": "afea950ddb13c03e34359ad8a4c86f24913f2693806e3ff1f4087b4285fd2af2",
"iris.tests.test_plot.TestPlotCoordinatesGiven.test_y.0": "afee9632de05c9d9f180d168c454a53e931b3e84954a3b8c85f94ce703ff7284",
"iris.tests.test_plot.TestPlotCoordinatesGiven.test_yx.0": "ea853f00957ac07c957ac0bf951a69f3c47c7a5f3a4127816b953e646b813761",
Expand Down Expand Up @@ -202,8 +202,8 @@
"iris.tests.test_plot.TestQuickplotPlot.test_x.0": "82ff950b7f81c0d6620199bcfc5e986695734da1816e1b2c85be2b65d96276d1",
"iris.tests.test_plot.TestQuickplotPlot.test_y.0": "a2fbb46e7f10c99f2013d863e46498dcd06c0d2798421fa5dd221e7789ff6f10",
"iris.tests.test_plot.TestQuickplotPlot.test_z.0": "a3ffc1de7e009c7030019786f438cde3810fd93c9b734a778ce47c9799b02731",
"iris.tests.test_plot.TestSimple.test_bounds.0": "ea856a85954a957ac17e954ac17a9d3a956ac07e3e80c07f3e857aa5c27d3f80",
"iris.tests.test_plot.TestSimple.test_points.0": "ea856a85957a957ac17e954ac17e1ea2950bc07e3e80c07f3e807a85c1ff3f81",
"iris.tests.test_plot.TestSimple.test_bounds.0": "ea856a85955a957ac17e954ac17a9d22956ac07e3e81c07f3e857aa5c27d3f80",
"iris.tests.test_plot.TestSimple.test_points.0": "ea856a85957a957ac17e954ac17e1fa2950ac07e3e80c07d3e847a85c1ff3f81",
"iris.tests.test_plot.TestSymbols.test_cloud_cover.0": "eb5291e494ad6e136b5291ec94ad6e136b5291ec94ad6e136b5291ec94ad6e13",
"iris.tests.test_quickplot.TestLabels.test_alignment.0": "be813fe0954ac07fc0ff3e81c03fc97a6d0094af3f80c17f36a53240d97f2d82",
"iris.tests.test_quickplot.TestLabels.test_contour.0": "a7fd955a7a016d1a3217c962e4819a56c96f3c859b624d2584de3a6999b662db",
Expand All @@ -220,12 +220,12 @@
"iris.tests.test_quickplot.TestPlotHist.test_horizontal.0": "b59cc3dadb433c24c4f166039438793591a7dbdcbcdc9ccc68c697a91b139131",
"iris.tests.test_quickplot.TestPlotHist.test_vertical.0": "bf80c7c6c07d7959647e343a33364b699589c6c64ec0312b9e227ad681ffcc68",
"iris.tests.test_quickplot.TestQuickplotCoordinatesGiven.test_non_cube_coordinate.0": "fe816a85857a957ac07f957ac07f3e80956ac07f3e80c07f3e813e85c07e3f80",
"iris.tests.test_quickplot.TestQuickplotCoordinatesGiven.test_tx.0": "ea856a95955a956ac17f950a807e3f4e951ac07e3f81c0ff3ea16aa1c0bd3e81",
"iris.tests.test_quickplot.TestQuickplotCoordinatesGiven.test_tx.1": "ea856a85957a957ac17e954ac17e1ea2950bc07e3e80c07f3e807a85c1ff3f81",
"iris.tests.test_quickplot.TestQuickplotCoordinatesGiven.test_tx.2": "eaf9eec9f729943032168d66d4db896e9567497b81304aedc96514ad8d18669a",
"iris.tests.test_quickplot.TestQuickplotCoordinatesGiven.test_tx.3": "a6fb4b967f00950eb00f9d0f900fcd62dc7868f2c1bb3a909c266e34daa52f6c",
"iris.tests.test_quickplot.TestQuickplotCoordinatesGiven.test_tx.4": "eaa9b549f756854ea0168d6ed556896fd8a909ed88290afdd9e97e008d6e2296",
"iris.tests.test_quickplot.TestQuickplotCoordinatesGiven.test_tx.5": "aad73e0df78085ac840195ac9528d9fad56cd8f2906c48f2d0ec7a536a1737f3",
"iris.tests.test_quickplot.TestQuickplotCoordinatesGiven.test_tx.0": "ea856a95955a956ac17f950a817e3fcc951ac07e3e81c07f7ea16a85c07e3e81",
"iris.tests.test_quickplot.TestQuickplotCoordinatesGiven.test_tx.1": "ea856a85957a957ac17e954ac17e1fa2950ac07e3e80c07d3e847a85c1ff3f81",
"iris.tests.test_quickplot.TestQuickplotCoordinatesGiven.test_tx.2": "eaf9e2c9ff60b43036168d6795c2892e95674b7b80304aedc8651ead99192eda",
"iris.tests.test_quickplot.TestQuickplotCoordinatesGiven.test_tx.3": "a2ff7892771d912cb4089d0ffd4b8d429c4049f3d1bb1a909c266e34dae56f68",
"iris.tests.test_quickplot.TestQuickplotCoordinatesGiven.test_tx.4": "eaa9f598b756a41e8056855e955689f9d9610be988290bfdd9fdfe0089562a61",
"iris.tests.test_quickplot.TestQuickplotCoordinatesGiven.test_tx.5": "ead7780cf7d3c5acb40095acd56999e2952899f2d5ec0bf3902c6a536a57b700",
"iris.tests.test_quickplot.TestQuickplotCoordinatesGiven.test_x.0": "a6fb958dff50c03e203598dca4c9cd26933f9cf3886e1de1dc047b4289ec2672",
"iris.tests.test_quickplot.TestQuickplotCoordinatesGiven.test_y.0": "a2ffb6127f0dc9992085d960c6748d3edb121ca49d6a1b048df34ce789ff7205",
"iris.tests.test_quickplot.TestQuickplotCoordinatesGiven.test_yx.0": "ea856a95957a957ac07e954ac17e3e86950bc17f3ea4c27d3e833ac1c1e03f80",
Expand Down