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

Incorrect Polygons for some filled contour plots #310

Closed
mikewalker92 opened this issue Aug 7, 2013 · 5 comments
Closed

Incorrect Polygons for some filled contour plots #310

mikewalker92 opened this issue Aug 7, 2013 · 5 comments

Comments

@mikewalker92
Copy link

The following code does not produce the desired plot.
Instead, this returns a green envelope shape spanning the entire map.

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

fname = iris.sample_data_path('uk_hires.pp')
cubes = iris.load(fname)
cube = cubes[0]

sub_cube = cube[2,5]

qplt.contourf(sub_cube, 43)
plt.show()

Plotting with less than 43 contours returns the expected results.
Plotting with different choices of sub cubes also produces the expected results.

@esc24
Copy link
Member

esc24 commented Aug 7, 2013

42 levels: 42levels
43 levels: 43levels

@pelson
Copy link
Member

pelson commented Jun 30, 2015

Looks like there are a number of problems with the geometries produced in this contour. One example:

from matplotlib.path import Path
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
import cartopy
import cartopy.crs as ccrs

sphere = ccrs.Globe(semimajor_axis=6371229.0,
                    semiminor_axis=6371229.0,
                    ellipse=None)
rp = ccrs.RotatedPole(177.5, 37.5, globe=sphere)
rp_geod = ccrs.RotatedGeodetic(177.5, 37.5, globe=sphere)

bad_path = Path._fast_from_codes_and_verts(np.array([[ 359.58648681640625  ,    1.6967999935150084],
       [ 359.58648681640625  ,    1.6967999935150146],
       [ 359.5999755859375   ,    1.7103000879287658],
       [ 359.5999755859375   ,    1.710300087928772 ],
       [ 359.5999755859375   ,    1.7238000631332397],
       [ 359.5999755859375   ,    1.7373000383377075],
       [ 359.5999755859375   ,    1.7508000135421753],
       [ 359.613494873046875 ,    1.7642999887466368],
       [ 359.613494873046875 ,    1.7642999887466431],
       [ 359.613494873046875 ,    1.7778000831604004],
       [ 359.613494873046875 ,    1.7778000831604066],
       [ 359.5999755859375   ,    1.7778000831604035],
       [ 359.5999755859375   ,    1.7778000831604004],
       [ 359.5999755859375   ,    1.7642999887466431],
       [ 359.5999755859375   ,    1.7508000135421753],
       [ 359.58648681640625  ,    1.7373000383377137],
       [ 359.58648681640625  ,    1.7373000383377075],
       [ 359.58648681640625  ,    1.7373000383377013],
       [ 359.5999755859375   ,    1.7238000631332397],
       [ 359.58648681640625  ,    1.7103000879287782],
       [ 359.58648681640625  ,    1.710300087928772 ],
       [ 359.58648681640625  ,    1.6967999935150146],
       [ 359.58648681640625  ,    1.6967999935150084]]),
            np.array([1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2], dtype=np.uint8))

ax = plt.axes(projection=rp)
patch = mpatches.PathPatch(bad_path, facecolor='red', alpha=0.2, transform=rp_geod)
ax.add_patch(patch)
ax.autoscale_view()
plt.show()

figure_1

@pelson
Copy link
Member

pelson commented Jun 30, 2015

Path reduced to:

verts = np.array([[ 359.5  ,    1.6967999935150084],
                  [ 359.5  ,    1.6967999935150146],
                  [ 359.613494873046875 ,    1.7642999887466368],
                  [ 359.613494873046875 ,    1.7642999887466431],
                  [ 359.5920764726345737,    1.7421173469387756],
                  [ 359.5  ,    1.6967999935150146],
                  [ 359.5  ,    1.6967999935150084]])
codes = [1, 2, 2, 2, 2, 2, 2]
bad_path = Path(verts, codes)

Seems highly likely that this is a threshold issue - changing some of the floats makes this case work again.

@pelson pelson modified the milestones: 0.13, 0.12 Jun 30, 2015
@pelson pelson modified the milestones: 0.16, 0.17 Nov 21, 2017
@pelson
Copy link
Member

pelson commented Feb 21, 2018

Whilst some of the broken down problems are resolved in v0.16, the original issue remains.

@QuLogic
Copy link
Member

QuLogic commented Oct 13, 2018

This seems fixed on master.

@QuLogic QuLogic closed this as completed Oct 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants