Solution of my previous topic: contourf creats white-like lines (or gaps)

Firstly, I want to thank Marius (Marius 't Hart-3) and Eric (efiring) for the
help on my question. Especially Eric, your advices about 'antialiased' gave
me the hint to get the solution.

In my previous topic "
contourf creats white-like lines (or gaps) between each two color patches ",
I attached two figures to show the bug-like problem of contourf plotting
function. The first one is created by contourf only, and the in second one,
I used contourf and contour together to fill up the gaps between each two
It seems a kind of solution to make the filled contour map better looking,
but I really don't like this messy way. So I posted the questionhere to find

Following Eric's suggestion

CS = contourf(Z)
for c in CS.collections:

the antialiased attributes of each polygon in the filled contour map is
changed to be unsmoothed, and the gaps are gone. This is much better way to
solve the gap problem, but I should do this every time after I plotting the
filled contour map. It's not the best solution.

1. Basic solution

I tried to study the arguments of contourf function to find the proper
parameter about antiliased, and there is one in the doc string:
    contourf-only keyword arguments:
      *antialiased*: [ True | False ]
        enable antialiasing
Good! Try this:
                CS = contourf(Z, antialiased=False)
Oops~~~ nothing happens, gaps are still there. Why? Bug?

I searched 'antialiased' in the file located in the
installed matplotlib package directory), and find this: (line 604 through
                col = collections.PolyCollection(nlist,
                                     antialiaseds = (self.antialiased,),
                                     edgecolors= 'none',
I changed the line 605
                                     antialiaseds = (self.antialiased,),
                                     antialiaseds = self.antialiased,
plotted the filled contourf map again:
                CS = contourf(Z, antialiased=False)
Wow~~~ gaps free.

I don't know if it is a bug or not, but edit it simply, works well.

2. Upgrade the solution

Don't like the unsmoothed edge? Still want the antialiased to be True?
OK, notice the line just under antialiaseds setting listed above?
it means no edge is plotted.

Go straight down to line 640:
here the face colors are set. Just below this line, I added one new line:
then plotted the filled contourf map anain, without setting
                CS = contourf(Z)
Aha, Mission accomplished.


View this message in context:
Sent from the matplotlib - users mailing list archive at