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

Antialiased contourf plot shows unexpected artifacts #4086

Closed
jamesp opened this issue Apr 8, 2021 · 4 comments · Fixed by #4150
Closed

Antialiased contourf plot shows unexpected artifacts #4086

jamesp opened this issue Apr 8, 2021 · 4 comments · Fixed by #4150

Comments

@jamesp
Copy link
Member

jamesp commented Apr 8, 2021

🐛 Bug Report

When plotting an iris cube with contourf in some circumstances an additional contour is shown. This appears to be related to the logic included by the antialiased option in iris.plot.contouf.

How To Reproduce

Steps to reproduce the behaviour:

  1. Contact @jamesp for data and reproduction script

Expected behaviour

Antialiased data should not show additional artifacts when plotting.

Screenshots

image

Environment

  • OS & Version: Linux
  • Iris Version: 3.0.1. Affects Iris >= 2.3
@bjlittle
Copy link
Member

bjlittle commented Apr 9, 2021

@jamesp What version of mpl are you using?

@jamesp
Copy link
Member Author

jamesp commented Apr 9, 2021

The antialiased artifact (additional contour) is present on all stack versions since Iris 1.13.

I've tested on matplotlib 2.2.3 and 3.3.4, both show the same additional contour. Setting antialiased=False restores the same behaviour as 1.13, which is what the user was running on previously.

I've tried to create a standardised test that reproduces the issue, but haven't achieved it yet, there does appear to be something pathological about the input data

@rcomer
Copy link
Member

rcomer commented May 11, 2021

Here is a minimal example:

import iris
import iris.quickplot as qplt
import numpy as np
import matplotlib.pyplot as plt


lats = np.linspace(-10, 10, 20)
lons_2d, lats_2d = np.meshgrid(lats, lats)

data = np.cos(lons_2d * np.pi/10.) + np.cos(lats_2d * np.pi/10.)
np.place(data, data < 0., 0.)

cube = iris.cube.Cube(data)
for dim, name in enumerate(['longitude', 'latitude']):
    cube.add_dim_coord(iris.coords.DimCoord(lats, standard_name=name, units='degrees'), dim)

levels = [0.2, 2, 20, 200]
colors = ['b', 'r', 'y']

qplt.contourf(cube, levels=levels, colors=colors)

contourf_antialias1
The problem seems to be triggered by a combination of

  • having zeros everywhere other than our desired feature
  • data values all being below the second level

If we pick level so that all the colours are used, all seems well

levels = [0.2, 0.5, 1, 2]
qplt.contourf(cube, levels=levels, colors=colors)

contourf_antialias2
Since iris.plot.contourf does some subsetting of levels and colors, the problem boils down to

sub_levels = [2, 20]
sub_colors = ['b', 'r']

qplt.contour(cube, levels=sub_levels, colors=sub_colors)

contourf_antialias3
which we also see if we plot directly with matplotlib

plt.contour(cube.data, levels=sub_levels, colors=sub_colors)

contourf_antialias4

@rcomer
Copy link
Member

rcomer commented May 11, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants