Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Contourf and transparency

830 views
Skip to first unread message

Pete

unread,
Sep 12, 2008, 11:30:38 AM9/12/08
to
Hi all
My basic question: is there a way to make filled contours (using 'contourf') semi-transparent?
I have searched on the site and on the net for a simple solution but can't find one.
I will expand a little.
I am working with a dynamic model. Each time step, I input a scanned image (jpg) of an ordnance survey map of an agricultural landscape. I would like to overlay a filled contour plot of some other data, but it seems I can't make the contours transparent. I have tried plotting the map, using 'hold on', and setting alpha to a value < 1, but this makes both layers transparent, and the map appears faded. I imagine it might be possible to save the contour plot as an rgb, then combine the two layers and fix the transparency then. However, I would rather not take this approach as I do not want the user to see an intermediate figure (the contour plot), only the combined figure. Is there perhaps some operation I can perform on the map jpg that would, for example, leave only polygon edges whilst inner areas are transparent? As you can probably tell, I am new to working with images in matlab, so any pointers would be greatly appreciated.

Yuri Geshelin

unread,
Sep 12, 2008, 2:54:02 PM9/12/08
to
Hi Pete,

You can apply alpha only to the top level, e.g.

clf, contourf(peaks), hold on
[c,h] = contourf(repmat(0.25*(1:49)-5.25,49,1));
ch = get(h,'child'); alpha(ch,0.2)

Yuri

"Pete " <petem...@gmail.com> wrote in message <gae1uu$232$1...@fred.mathworks.com>...

Steven Lord

unread,
Sep 12, 2008, 5:12:43 PM9/12/08
to

"Pete " <petem...@gmail.com> wrote in message
news:gae1uu$232$1...@fred.mathworks.com...


z = peaks;
[c,h] = contourf(z); clabel(c,h), colorbar
% Set the figure Renderer to OpenGL, which supports transparency
set(gcf, 'Renderer', 'OpenGL');
% Find all the objects that are children of the contourgroup that have the
FaceAlpha property
alphable = findobj(h, '-property', 'FaceAlpha');
for k = [1:-0.1:0.1 0.1:0.1:1]
% Change the FaceAlpha property, which will change the objects'
transparency
set(alphable, 'FaceAlpha', k);
pause(0.5)
end


--
Steve Lord
sl...@mathworks.com


Pete

unread,
Sep 13, 2008, 3:10:04 AM9/13/08
to
Great work guys - much appreciated.

Francis Burton

unread,
Sep 15, 2008, 4:14:44 PM9/15/08
to
In article <gafp0c$i24$1...@fred.mathworks.com>,

Pete <petem...@gmail.com> wrote:
>Great work guys - much appreciated.

When I did this a while back I ran into a problem with
the colours of the semi-transparent contours appearing
incorrect (the wrong hue in some cases). This turned out
to be because the contour objects with the FaceAlpha
property were stacked on top of each other, so that when
they were made semi-transparent any object(s) below
would contribute to the final colour. In the end, I
used getframe to capture the opaque contourf plot and
then display the resulting image semi-transparently over
the background image.

I don't know if this problem applies to the current
version of MATLAB - you might want to check this if the
filled contour colours are important.

Francis

0 new messages