Grid appearing on pcolormesh global images

2,405 views
Skip to first unread message

rebecca....@metoffice.gov.uk

unread,
Jun 24, 2013, 11:36:28 AM6/24/13
to scitoo...@googlegroups.com
Hi,

I am creating images like the one below, recently when my images are created they seem to have a fine grid across them which isn't supposed to be there.  If you look along the left hand edge you can see where the grid doesn't cover the image and how I am expecting the whole image to look.
Has anyone had this problem recently? I have been using the testing version of iris and we wondered if that could be having an effect?

Thanks!
Becky

gridplot.png

Andrew Dawson

unread,
Jun 26, 2013, 3:49:53 AM6/26/13
to scitoo...@googlegroups.com
Hi Becky

Can you give us a few more details. How are you generating the plot exactly, I assume using iris.plot.pcolormesh? Is it just one plot or are there multiple plots drawn over one another, it is hard to tell just by looking? Also, do you have a simple example that reproduces this?

You say this happened recently, and that you are using the development version of iris, so I assume the same program produced the expected result with a previous version of iris? If so do you know which version of iris it last worked with?

It might also be useful to know which versions of cartopy and matplotlib you are using:

import matplotlib
print matplotlib.__version__
import cartopy
print cartopy.__version__

esc24

unread,
Jun 26, 2013, 5:20:58 AM6/26/13
to scitoo...@googlegroups.com
I believe this is a matplotlib issue relating to alpha levels when drawing two polygons that share a common edge. The two alpha levels e.g. 0.5 and 0.5 associated with semi-transparent polygons add to give 1.0 resulting in a non-transparent line. In the case of pcolormesh this leads to a grid. See http://matplotlib.1069221.n5.nabble.com/Quadmesh-with-alpha-without-the-nasty-edge-effects-td41039.html

bjlittle

unread,
Jun 26, 2013, 5:21:42 AM6/26/13
to scitoo...@googlegroups.com
Hi Becky,

As Andrew mentioned, if you can provide more details, then that would be helpful ...

Kinda looks like you're plotting a pcolormesh over a global filled contour ... just as a sanity check, are you sure that the bounds for the pcolormesh are not misaligned? i.e. the cropped edges may be the result of the outer edge bounds not having full coverage.

Hmmm or it might be due to circularity ... is your longitude coordinate circular?

Becky Stretton

unread,
Jun 26, 2013, 11:13:40 AM6/26/13
to scitoo...@googlegroups.com
Hi,

Matthew has put together some code to demonstrate the problem more clearly:

import matplotlib.pyplot as plt
import pylab

zhuge  = pylab.rand(100,100)

print "alpha =1.0"
c = plt.pcolormesh(zhuge)
plt.show()

print "alpha =0.6"
c = plt.pcolormesh(zhuge, alpha=0.6)
plt.show()


my matplotlib is 1.2.0rc2 and cartopy is 0.7.0

I think Ed has also set up a work order for this as a matplotlib issue.

Thanks!
Becky

reductionist denexo

unread,
Jan 23, 2018, 7:20:01 AM1/23/18
to SciTools (iris, cartopy, cf_units, etc.) - https://github.com/scitools
Hello, years after, and the problem is not resolved in the latest version of matplotlib.
Any idea how to get rid of these grid lines?

Georgina L

unread,
Mar 21, 2018, 5:53:52 PM3/21/18
to SciTools (iris, cartopy, cf_units, etc.) - https://github.com/scitools
Has anyone figured this out yet? I'm getting the same problem and I don't understand why. When I run the code in jupyter notebooks there's no problem, but running a script from the terminal puts the grid there?

Georgina L

unread,
Mar 21, 2018, 6:01:36 PM3/21/18
to SciTools (iris, cartopy, cf_units, etc.) - https://github.com/scitools
I've worked out it only happens when I save the plot as a pdf. Saving it as a png file removes the grid lines. Not ideal (as I want a pdf), but this will hopefully be a good workaround for anyone else.
If anyone has a solution which allows you to save it as a pdf without gridlines please let me know :)

Klaus Zimmermann

unread,
Mar 22, 2018, 5:51:02 AM3/22/18
to scitoo...@googlegroups.com
Hi Georgina,

these problems come from individual quadrilaterals being drawn.
Depending on the renderer, e.g. your pdf viewer, several things can go
wrong, like a little gap left for border lines, or overlapping boxes.
So, technically matplotlib might not be at fault. Also, since you
mention pdf this might be a slightly different issue from the one
mentioned below, which definitely comes from the alpha.

Regardless, here some practical advice.

For the alpha problem in interactive viewing, check out [1] for a
workaround that will require some fiddling depending on colormap, length
scales of the plot, and backend.

For your pdf problem you might try to save the figure as a pdf, but have
the mesh rasterized. If the mesh is relatively high resolution or
parallel to the axes this could be more appropriate anyway and you get
the best of both worlds: Space efficient high resolution maps that scale
well, and crisp annotations, labels, axes ticks, etc.
To achieve this just do

mesh = iris.quickplot.pcolormesh(cube)
mesh.set_rasterized(True)

before the saving.

Cheers
Klaus

[1]
https://stackoverflow.com/questions/20678817/pyplot-pcolormesh-confused-when-alpha-not-1
> --
> You received this message because you are subscribed to the Google
> Groups "SciTools (iris, cartopy, cf_units, etc.) -
> https://github.com/scitools" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to scitools-iri...@googlegroups.com
> <mailto:scitools-iri...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages