problems with contourf & alpha

Im having an issue where contourf is producing visible defects in the shaded contours (within png output) with alpha values that are less then 1.0.

Ive attached two images.
- the first image,contourf_no_alpha.png, shows my contour plot with the alpha value left at its default
(i.e.,alpha is not set, so alpha=1.0).

- the second image, contourf_with_alpha.png, shows the same contoured data, yet with the alpha set to 0.75.
There are vertical lines visible where the contours are apparently being closed/joined?

I added pink contour lines in order to show that these vertical lines are NOT actually part of the contour.

these are the commands that I used:

Z=create_my_data()

...

# image 1 (contourf_no_alpha.png)
cs=m.contourf(X,Y,Z,lev)
cs=m.contour(X,Y,Z,lev,colors='pink'linewidths=1.5)

# image 2 (contourf_with_alpha.png)
cs=m.contourf(X,Y,Z,lev,alpha=0.75)
cs=m.contour(X,Y,Z,lev,colors='pink',linewidths=1.5)

Im running the latest versions of basemap&matplotlib.

How can I remove these vertical defects while still being able to use "semi-transparent" alpha values?

Please help,

Thanks,

P.Romero

contourf_no_alpha.png

contourf_with_alpha.png

···

_________________________________________________________________
Hotmail® is up to 70% faster. Now good news travels really fast.
http://windowslive.com/online/hotmail?ocid=TXT_TAGLM_WL_HM_70faster_032009

Pablo Romero wrote:

Im having an issue where contourf is producing visible defects in the shaded contours (within png output) with alpha values that are less then 1.0.

Pablo,

See [Matplotlib-users] A contourf bug?
and my reply to that.

I have an idea about how to solve the problem, but it is not trivial and won't happen soon--unless someone else wants to work on it.

Filled contours are surprisingly hard to get right!

Eric

···

Ive attached two images.
- the first image,contourf_no_alpha.png, shows my contour plot with the alpha value left at its default
(i.e.,alpha is not set, so alpha=1.0).

- the second image, contourf_with_alpha.png, shows the same contoured data, yet with the alpha set to 0.75.
There are vertical lines visible where the contours are apparently being closed/joined?

I added pink contour lines in order to show that these vertical lines are NOT actually part of the contour.

these are the commands that I used:

Z=create_my_data()

...

# image 1 (contourf_no_alpha.png)
cs=m.contourf(X,Y,Z,lev)
cs=m.contour(X,Y,Z,lev,colors='pink'linewidths=1.5)

# image 2 (contourf_with_alpha.png)
cs=m.contourf(X,Y,Z,lev,alpha=0.75)
cs=m.contour(X,Y,Z,lev,colors='pink',linewidths=1.5)

Im running the latest versions of basemap&matplotlib.

How can I remove these vertical defects while still being able to use "semi-transparent" alpha values?

Please help,

Thanks,

P.Romero
_________________________________________________________________
Hotmail® is up to 70% faster. Now good news travels really fast. http://windowslive.com/online/hotmail?ocid=TXT_TAGLM_WL_HM_70faster_032009

------------------------------------------------------------------------

------------------------------------------------------------------------

------------------------------------------------------------------------

------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com

------------------------------------------------------------------------

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

Reading Eric's reply on the previous email, my impression is that
contourf is not supposed to draw the boundary (no stroke!). But it
seems it still does.

for c in cs.collections:
    c.set_edgecolor("none")

After this, I can get rid of the vertical lines.
I can see slight gaps between filled regions, though.

While contourf create PolyCollection with edgecolors="none", the
edgecolor are overridden later by the set_color call inside the
ContourSet.changed method.

It may be better to draw the boundary for alpha=1, but better not otherwise.

Anyhow, there is a little bug in how alpha value is treated in the
contourf(maybe contour also).

In [2]: CS = plt.contourf(X, Y, Z,alpha = .7)

In [3]: print CS.collections[0].get_facecolor()
[[ 0. 0. 0.82085561 0.49 ]]

Note that the alpha of the resulting facecolor is 0.7**2.
It seems that both PolygonCollection and ContourSet are applying the
alpha value.
I may able to look at this sometime tomorrow, but feel free to take over.

Regards,

-JJ

···

On Tue, Mar 17, 2009 at 2:55 AM, Eric Firing <efiring@...202...> wrote:

Pablo Romero wrote:

Im having an issue where contourf is producing visible defects in the shaded contours (within png output) with alpha values that are less then 1.0.

Pablo,

See
[Matplotlib-users] A contourf bug?
and my reply to that.

I have an idea about how to solve the problem, but it is not trivial and
won't happen soon--unless someone else wants to work on it.

Filled contours are surprisingly hard to get right!

Eric

Ive attached two images.
- the first image,contourf_no_alpha.png, shows my contour plot with the alpha value left at its default
(i.e.,alpha is not set, so alpha=1.0).

- the second image, contourf_with_alpha.png, shows the same contoured data, yet with the alpha set to 0.75.
There are vertical lines visible where the contours are apparently being closed/joined?

I added pink contour lines in order to show that these vertical lines are NOT actually part of the contour.

these are the commands that I used:

Z=create_my_data()

...

# image 1 (contourf_no_alpha.png)
cs=m.contourf(X,Y,Z,lev)
cs=m.contour(X,Y,Z,lev,colors='pink'linewidths=1.5)

# image 2 (contourf_with_alpha.png)
cs=m.contourf(X,Y,Z,lev,alpha=0.75)
cs=m.contour(X,Y,Z,lev,colors='pink',linewidths=1.5)

Im running the latest versions of basemap&matplotlib.

How can I remove these vertical defects while still being able to use "semi-transparent" alpha values?

Please help,

Thanks,

P.Romero
_________________________________________________________________
Hotmail® is up to 70% faster. Now good news travels really fast.
http://windowslive.com/online/hotmail?ocid=TXT_TAGLM_WL_HM_70faster_032009

------------------------------------------------------------------------

------------------------------------------------------------------------

------------------------------------------------------------------------

------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com

------------------------------------------------------------------------

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

Jae-Joon Lee wrote:

Reading Eric's reply on the previous email, my impression is that
contourf is not supposed to draw the boundary (no stroke!). But it
seems it still does.

for c in cs.collections:
    c.set_edgecolor("none")

After this, I can get rid of the vertical lines.
I can see slight gaps between filled regions, though.

I am not sure they are really gaps, but it looks to me like there is no perfect way to get the region boundaries rendered under all conditions--any combination of settings of antialiasing, boundary stroking, and alpha, can produce visual artifacts of the rendering or errors in the representation of data. Different renderers handle the same boundaries in different ways, so that sometimes an artifact will be annoying with one renderer and absent with another.

While contourf create PolyCollection with edgecolors="none", the
edgecolor are overridden later by the set_color call inside the
ContourSet.changed method.

It may be better to draw the boundary for alpha=1, but better not otherwise.

It looks to me like there are always compromises, but overall it is best for contour not to draw the boundaries at all. I think that was my intention all along, and I suspect it was accidentally thwarted along the way by some change--but I have not tried to track down the history. What matters is only how we can get the best behavior and the best API. I have made some minimal changes to fix what seem to me to be blatent bugs (so I made the changes in the 98.5 maint and propagated them via svnmerge). The code could benefit from a much more thorough review and testing, and probably some substantial changes. It may be that some tweaking of antialiased on/off, whether and how to draw boundaries, etc. will always have to be left to the user, depending on backend used and the characteristics of the plot.

Anyhow, there is a little bug in how alpha value is treated in the
contourf(maybe contour also).

I fixed this also--the problem was in colors.py, so it was quite general.

Thanks for finding these problems! I was completely wrong in my original diagnosis of the contourf problem with alpha. The solution I had in mind, which is to process the path information so as to generate multiply-connected regions instead of using branch cuts, may still have some advantages--in particular, it would make it possible to stroke the boundaries, and/or to use the same boundaries for selected line contours, instead of having to calculate them independently (and sometimes differently) with a call to contour. It is my understanding that all backends now should be able to handle multiply-connected regions.

Eric

···

In [2]: CS = plt.contourf(X, Y, Z,alpha = .7)

In [3]: print CS.collections[0].get_facecolor()
[[ 0. 0. 0.82085561 0.49 ]]

Note that the alpha of the resulting facecolor is 0.7**2.
It seems that both PolygonCollection and ContourSet are applying the
alpha value.
I may able to look at this sometime tomorrow, but feel free to take over.

Regards,

-JJ