|
From: kippertoffee <fly...@go...> - 2008-08-06 12:31:33
|
Hello, I am attempting to overlay a filled contour over a custom image. I have managed to get something basic working, but i have encountered a problem: When the contourf plot is set to semi-transparent there are visible lines joining the bottom of the plot and the filled contour edges. I have attached an image of the plot. http://img232.imageshack.us/my.php?image=spambs6.png spam.png The code i have used is below; please bear in mind I am not a programmer, so if the code seems botched, that's because it is. ############################### import matplotlib.pyplot as plt from pylab import * try: import Image except ImportError, exc: raise SystemExit("PIL must be installed to run this example") lena = Image.open('lena.jpg') dpi = rcParams['figure.dpi'] figsize = lena.size[0]/dpi, lena.size[1]/dpi fig = plt.figure(figsize=figsize) #fig.patch.set_alpha(0.5) ax = fig.add_subplot(111) #ax.patch.set_alpha(0.5) ax.imshow(lena, origin='lower') ax.contourf(z2,[10,15,20,25,30,35,40,45,50,55,60,65],alpha=0.7) show() ############################ Can anyone help me with this problem? Thanks for reading, Pete. -- View this message in context: http://www.nabble.com/Filled-contour-transparency-issue-tp18850187p18850187.html Sent from the matplotlib - users mailing list archive at Nabble.com. |
|
From: Michael D. <md...@st...> - 2008-08-06 13:12:14
|
This is a known issue with the contouring code. It's borrowed from an earlier plotting package called GIST, and assumes that the renderer can not handle compound polygons (for example, donut-shaped, with both an inner and outer edge). So instead, it draws "cuts" that go from the inner to the outer edge. When anti-aliasing is turned on, there is a slight overlap or "drawing twice" along this edge which creates what looks like a line. Unfortunately, this can't be remedied by plotting the contour fills and then plotting the contour edges over top (as is done is contourf_demo.py). As of matplotlib 0.98.x, matplotlib itself can handle compound paths, so we no longer need the cuts. I've made a few attempts at updating the contouring code to avoid them, but got nowhere. The contouring code is very opaque, almost magical code, and most who've dared to go in have barely made it out alive... ;) That said, a fresh pair of eyes may have what it takes... As for a workaround, you could render your contour as opaque, save that out as an image and read it back in. The code to do that won't be pretty, but it just might work. Cheers, Mike kippertoffee wrote: > Hello, > > I am attempting to overlay a filled contour over a custom image. > > I have managed to get something basic working, but i have encountered a > problem: > > When the contourf plot is set to semi-transparent there are visible lines > joining the bottom of the plot and the filled contour edges. I have attached > an image of the plot. > > http://img232.imageshack.us/my.php?image=spambs6.png spam.png > > The code i have used is below; please bear in mind I am not a programmer, so > if the code seems botched, that's because it is. > > ############################### > > import matplotlib.pyplot as plt > from pylab import * > try: > import Image > except ImportError, exc: > raise SystemExit("PIL must be installed to run this example") > > lena = Image.open('lena.jpg') > dpi = rcParams['figure.dpi'] > figsize = lena.size[0]/dpi, lena.size[1]/dpi > > fig = plt.figure(figsize=figsize) > #fig.patch.set_alpha(0.5) > ax = fig.add_subplot(111) > #ax.patch.set_alpha(0.5) > > ax.imshow(lena, origin='lower') > > ax.contourf(z2,[10,15,20,25,30,35,40,45,50,55,60,65],alpha=0.7) > show() > ############################ > > > Can anyone help me with this problem? > > Thanks for reading, > Pete. > -- Michael Droettboom Science Software Branch Operations and Engineering Division Space Telescope Science Institute Operated by AURA for NASA |
|
From: kippertoffee <fly...@go...> - 2008-08-06 17:49:29
|
Thank you for your reply Michael. Is it possible to make the lines in the contourf plot completely transparent using an alpha setting? That would make a reasonable workaround as I intend to overlay black contours anyway. I've had a look at the source but it is way beyond me; I am a mere dabbler. Cheers, Pete. Michael Droettboom-3 wrote: > > This is a known issue with the contouring code. It's borrowed from an > earlier plotting package called GIST, and assumes that the renderer can > not handle compound polygons (for example, donut-shaped, with both an > inner and outer edge). So instead, it draws "cuts" that go from the > inner to the outer edge. When anti-aliasing is turned on, there is a > slight overlap or "drawing twice" along this edge which creates what > looks like a line. Unfortunately, this can't be remedied by plotting > the contour fills and then plotting the contour edges over top (as is > done is contourf_demo.py). > > As of matplotlib 0.98.x, matplotlib itself can handle compound paths, so > we no longer need the cuts. I've made a few attempts at updating the > contouring code to avoid them, but got nowhere. The contouring code is > very opaque, almost magical code, and most who've dared to go in have > barely made it out alive... ;) That said, a fresh pair of eyes may have > what it takes... > > As for a workaround, you could render your contour as opaque, save that > out as an image and read it back in. The code to do that won't be > pretty, but it just might work. > > Cheers, > Mike > > kippertoffee wrote: >> Hello, >> >> I am attempting to overlay a filled contour over a custom image. >> >> I have managed to get something basic working, but i have encountered a >> problem: >> >> When the contourf plot is set to semi-transparent there are visible lines >> joining the bottom of the plot and the filled contour edges. I have >> attached >> an image of the plot. >> >> http://img232.imageshack.us/my.php?image=spambs6.png spam.png >> >> The code i have used is below; please bear in mind I am not a programmer, >> so >> if the code seems botched, that's because it is. >> >> ############################### >> >> import matplotlib.pyplot as plt >> from pylab import * >> try: >> import Image >> except ImportError, exc: >> raise SystemExit("PIL must be installed to run this example") >> >> lena = Image.open('lena.jpg') >> dpi = rcParams['figure.dpi'] >> figsize = lena.size[0]/dpi, lena.size[1]/dpi >> >> fig = plt.figure(figsize=figsize) >> #fig.patch.set_alpha(0.5) >> ax = fig.add_subplot(111) >> #ax.patch.set_alpha(0.5) >> >> ax.imshow(lena, origin='lower') >> >> ax.contourf(z2,[10,15,20,25,30,35,40,45,50,55,60,65],alpha=0.7) >> show() >> ############################ >> >> >> Can anyone help me with this problem? >> >> Thanks for reading, >> Pete. > > > -- View this message in context: http://www.nabble.com/Filled-contour-transparency-issue-tp18850187p18856313.html Sent from the matplotlib - users mailing list archive at Nabble.com. |
|
From: Michael D. <md...@st...> - 2008-08-06 17:54:45
|
It doesn't seem to matter whether the filled contours are drawn with edges or not -- the cuts are still visible because they're caused by over-drawing of the fill. (You can set linewidth=0 to try this.) But maybe I misunderstand your question. Cheers, Mike kippertoffee wrote: > Thank you for your reply Michael. > > Is it possible to make the lines in the contourf plot completely transparent > using an alpha setting? That would make a reasonable workaround as I intend > to overlay black contours anyway. > > I've had a look at the source but it is way beyond me; I am a mere dabbler. > > Cheers, > Pete. > > > Michael Droettboom-3 wrote: > >> This is a known issue with the contouring code. It's borrowed from an >> earlier plotting package called GIST, and assumes that the renderer can >> not handle compound polygons (for example, donut-shaped, with both an >> inner and outer edge). So instead, it draws "cuts" that go from the >> inner to the outer edge. When anti-aliasing is turned on, there is a >> slight overlap or "drawing twice" along this edge which creates what >> looks like a line. Unfortunately, this can't be remedied by plotting >> the contour fills and then plotting the contour edges over top (as is >> done is contourf_demo.py). >> >> As of matplotlib 0.98.x, matplotlib itself can handle compound paths, so >> we no longer need the cuts. I've made a few attempts at updating the >> contouring code to avoid them, but got nowhere. The contouring code is >> very opaque, almost magical code, and most who've dared to go in have >> barely made it out alive... ;) That said, a fresh pair of eyes may have >> what it takes... >> >> As for a workaround, you could render your contour as opaque, save that >> out as an image and read it back in. The code to do that won't be >> pretty, but it just might work. >> >> Cheers, >> Mike >> >> kippertoffee wrote: >> >>> Hello, >>> >>> I am attempting to overlay a filled contour over a custom image. >>> >>> I have managed to get something basic working, but i have encountered a >>> problem: >>> >>> When the contourf plot is set to semi-transparent there are visible lines >>> joining the bottom of the plot and the filled contour edges. I have >>> attached >>> an image of the plot. >>> >>> http://img232.imageshack.us/my.php?image=spambs6.png spam.png >>> >>> The code i have used is below; please bear in mind I am not a programmer, >>> so >>> if the code seems botched, that's because it is. >>> >>> ############################### >>> >>> import matplotlib.pyplot as plt >>> from pylab import * >>> try: >>> import Image >>> except ImportError, exc: >>> raise SystemExit("PIL must be installed to run this example") >>> >>> lena = Image.open('lena.jpg') >>> dpi = rcParams['figure.dpi'] >>> figsize = lena.size[0]/dpi, lena.size[1]/dpi >>> >>> fig = plt.figure(figsize=figsize) >>> #fig.patch.set_alpha(0.5) >>> ax = fig.add_subplot(111) >>> #ax.patch.set_alpha(0.5) >>> >>> ax.imshow(lena, origin='lower') >>> >>> ax.contourf(z2,[10,15,20,25,30,35,40,45,50,55,60,65],alpha=0.7) >>> show() >>> ############################ >>> >>> >>> Can anyone help me with this problem? >>> >>> Thanks for reading, >>> Pete. >>> >> >> > > -- Michael Droettboom Science Software Branch Operations and Engineering Division Space Telescope Science Institute Operated by AURA for NASA |
|
From: peter w. <fly...@go...> - 2008-08-06 18:28:07
|
No michael, that is what I was suggesting. Shame it doesn't work. I'm looking at using Enthoughts Chaco to do it. It's takes a bit more to get it doing what I want though, and I don't know if it does alpha transparency at all. Thanks for your help. Pete 2008/8/6 Michael Droettboom <md...@st...> > It doesn't seem to matter whether the filled contours are drawn with edges > or not -- the cuts are still visible because they're caused by over-drawing > of the fill. (You can set linewidth=0 to try this.) But maybe I > misunderstand your question. > > Cheers, > Mike > > > kippertoffee wrote: > >> Thank you for your reply Michael. >> >> Is it possible to make the lines in the contourf plot completely >> transparent >> using an alpha setting? That would make a reasonable workaround as I >> intend >> to overlay black contours anyway. >> >> I've had a look at the source but it is way beyond me; I am a mere >> dabbler. >> >> Cheers, >> Pete. >> >> >> Michael Droettboom-3 wrote: >> >> >>> This is a known issue with the contouring code. It's borrowed from an >>> earlier plotting package called GIST, and assumes that the renderer can not >>> handle compound polygons (for example, donut-shaped, with both an inner and >>> outer edge). So instead, it draws "cuts" that go from the inner to the >>> outer edge. When anti-aliasing is turned on, there is a slight overlap or >>> "drawing twice" along this edge which creates what looks like a line. >>> Unfortunately, this can't be remedied by plotting the contour fills and >>> then plotting the contour edges over top (as is done is contourf_demo.py). >>> >>> As of matplotlib 0.98.x, matplotlib itself can handle compound paths, so >>> we no longer need the cuts. I've made a few attempts at updating the >>> contouring code to avoid them, but got nowhere. The contouring code is very >>> opaque, almost magical code, and most who've dared to go in have barely made >>> it out alive... ;) That said, a fresh pair of eyes may have what it >>> takes... >>> >>> As for a workaround, you could render your contour as opaque, save that >>> out as an image and read it back in. The code to do that won't be pretty, >>> but it just might work. >>> >>> Cheers, >>> Mike >>> >>> kippertoffee wrote: >>> >>> >>>> Hello, >>>> >>>> I am attempting to overlay a filled contour over a custom image. >>>> >>>> I have managed to get something basic working, but i have encountered a >>>> problem: >>>> >>>> When the contourf plot is set to semi-transparent there are visible >>>> lines >>>> joining the bottom of the plot and the filled contour edges. I have >>>> attached >>>> an image of the plot. >>>> >>>> http://img232.imageshack.us/my.php?image=spambs6.png spam.png >>>> The code i have used is below; please bear in mind I am not a >>>> programmer, >>>> so >>>> if the code seems botched, that's because it is. >>>> >>>> ############################### >>>> >>>> import matplotlib.pyplot as plt >>>> from pylab import * >>>> try: >>>> import Image >>>> except ImportError, exc: >>>> raise SystemExit("PIL must be installed to run this example") >>>> >>>> lena = Image.open('lena.jpg') >>>> dpi = rcParams['figure.dpi'] >>>> figsize = lena.size[0]/dpi, lena.size[1]/dpi >>>> >>>> fig = plt.figure(figsize=figsize) >>>> #fig.patch.set_alpha(0.5) >>>> ax = fig.add_subplot(111) >>>> #ax.patch.set_alpha(0.5) >>>> >>>> ax.imshow(lena, origin='lower') >>>> >>>> ax.contourf(z2,[10,15,20,25,30,35,40,45,50,55,60,65],alpha=0.7) >>>> show() >>>> ############################ >>>> >>>> >>>> Can anyone help me with this problem? >>>> >>>> Thanks for reading, >>>> Pete. >>>> >>>> >>> >>> >>> >> >> >> > > -- > Michael Droettboom > Science Software Branch > Operations and Engineering Division > Space Telescope Science Institute > Operated by AURA for NASA > > |
|
From: John H. <jd...@gm...> - 2008-08-06 19:02:04
|
On Wed, Aug 6, 2008 at 1:28 PM, peter websdell <fly...@go...> wrote: > No michael, that is what I was suggesting. Shame it doesn't work. > > I'm looking at using Enthoughts Chaco to do it. It's takes a bit more to get > it doing what I want though, and I don't know if it does alpha transparency > at all. I believe chaco uses the same contouring routine as mpl does, though I haven't verified this recently. JDH |