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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contourf Antialias Fix #4150

Merged
merged 4 commits into from
May 25, 2021
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
4 changes: 4 additions & 0 deletions docs/src/whatsnew/latest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:`4150`)


💣 Incompatible Changes
=======================
Expand Down
2 changes: 1 addition & 1 deletion lib/iris/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions lib/iris/tests/unit/plot/test_contourf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()