From 68f203229b04adad479aa505117c8fdb72beb579 Mon Sep 17 00:00:00 2001 From: Ruth Comer Date: Sun, 16 May 2021 16:22:07 +0100 Subject: [PATCH 1/4] check data max --- lib/iris/plot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/iris/plot.py b/lib/iris/plot.py index cc06c98afc..3cf0040035 100644 --- a/lib/iris/plot.py +++ b/lib/iris/plot.py @@ -1082,7 +1082,7 @@ def contourf(cube, *args, **kwargs): colors = colors[:-1] else: colors = colors[:-1] - if len(levels) > 0: + if len(levels) > 0 and cube.data.max() > levels[0]: # Draw the lines just *below* the polygons to ensure we minimise # any boundary shift. zorder = result.collections[0].zorder - 0.1 From b30e57a291f67c6aecf370abbbf32cb0bb6b7069 Mon Sep 17 00:00:00 2001 From: Ruth Comer Date: Sun, 23 May 2021 11:59:46 +0100 Subject: [PATCH 2/4] add test --- lib/iris/tests/unit/plot/test_contourf.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/lib/iris/tests/unit/plot/test_contourf.py b/lib/iris/tests/unit/plot/test_contourf.py index 0429b94c47..78f138c0da 100644 --- a/lib/iris/tests/unit/plot/test_contourf.py +++ b/lib/iris/tests/unit/plot/test_contourf.py @@ -12,6 +12,8 @@ from unittest import mock import numpy as np +import matplotlib +import matplotlib.pyplot as plt from iris.tests.stock import simple_2d from iris.tests.unit.plot import TestGraphicStringCoord, MixinCoords @@ -75,5 +77,26 @@ def setUp(self): self.draw_func = iplt.contourf +@tests.skip_plot +class TestAntialias(tests.IrisTest): + def test_skip_contour(self): + # Contours should not be added if data is all below second level. See #4086. + cube = simple_2d() + + levels = [5, 15, 20, 200] + colors = ["b", "r", "y"] + + iplt.contourf(cube, levels=levels, colors=colors, antialiased=True) + + ax = plt.gca() + # Expect 3 PathCollection objects (one for each colour) and no LineCollection + # objects. + for collection in ax.collections: + self.assertIsInstance( + collection, matplotlib.collections.PathCollection + ) + self.assertEqual(len(ax.collections), 3) + + if __name__ == "__main__": tests.main() From 7a3621d0fcb7406733827aa3b4f4e5617bd4d8fa Mon Sep 17 00:00:00 2001 From: Ruth Comer Date: Sun, 23 May 2021 12:17:30 +0100 Subject: [PATCH 3/4] whatsnew --- docs/src/whatsnew/latest.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/src/whatsnew/latest.rst b/docs/src/whatsnew/latest.rst index 7c5b1f04ae..c1031d3aec 100644 --- a/docs/src/whatsnew/latest.rst +++ b/docs/src/whatsnew/latest.rst @@ -62,6 +62,10 @@ This document explains the changes made to Iris for this release #. `@gcaria`_ fixed :meth:`~iris.cube.Cube.ancillary_variable_dims` to also accept the string name of a :class:`~iris.coords.AncillaryVariable`. (:pull:`3931`) +#. `@rcomer`_ modified :func:`~iris.plot.contourf` to skip the special handling for + antialiasing when data values are too low for it to have an effect. This caused + unexpected artifacts in some edge cases, as shown at :issue:`4086`. (:pull:`4148`) + 💣 Incompatible Changes ======================= From 4fc7e7bdb8fdb4e240f3dc4408f5d69cf5fd35ec Mon Sep 17 00:00:00 2001 From: Ruth Comer Date: Sun, 23 May 2021 12:32:25 +0100 Subject: [PATCH 4/4] fix PR number --- docs/src/whatsnew/latest.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/whatsnew/latest.rst b/docs/src/whatsnew/latest.rst index c1031d3aec..3caf386ef6 100644 --- a/docs/src/whatsnew/latest.rst +++ b/docs/src/whatsnew/latest.rst @@ -64,7 +64,7 @@ This document explains the changes made to Iris for this release #. `@rcomer`_ modified :func:`~iris.plot.contourf` to skip the special handling for antialiasing when data values are too low for it to have an effect. This caused - unexpected artifacts in some edge cases, as shown at :issue:`4086`. (:pull:`4148`) + unexpected artifacts in some edge cases, as shown at :issue:`4086`. (:pull:`4150`) 💣 Incompatible Changes