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 "
http://old.nabble.com/contourf-creats-white-like-lines-(or-gaps)-between-each-two-color-patches-tp27982822p28210898.html
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
patches.
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
answers.

Following Eric's suggestion

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

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 contour.py(this file located in the
installed matplotlib package directory), and find this: (line 604 through
607)
                col = collections.PolyCollection(nlist,
                                     antialiaseds = (self.antialiased,),
                                     edgecolors= 'none',
                                     alpha=self.alpha)
I changed the line 605
                                     antialiaseds = (self.antialiased,),
to
                                     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?
                                    edgecolors='none',
it means no edge is plotted.

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

ยทยทยท

--
View this message in context: http://old.nabble.com/Solution-of-my-previous-topic%3A-contourf-creats-white-like-lines-(or-gaps)-tp28219185p28219185.html
Sent from the matplotlib - users mailing list archive at Nabble.com.