Plot opaque element above transparent object

2 views (last 30 days)
Hi, I am plotting inversion results in a pcolor-plot, where I specify the transparency of each data point in dependance on the certainty of the model parameter. NaN is assigned to some model parameters, which appear white. Due to the resolution of the inversion grid, the boundary between the areas for which I have values and the NaN area appears very blocky.
In a plot that uses no transpareny, I can easily plot a white polygon with the "fill"-command which results in a sharp boundary. However, when I plot the white polygon with FaceALpha=1 above transparent elements, I can still see those elements below the polygon.
Here is an example that shows the effect:
clear all
close all
figure
polygon1=fill([1 3 3 1],[1 1 3 3],'r','FaceALpha',0.5);
hold on
polygon2=fill([2 4 4 2],[2 2 4 4],'b','FaceALpha',1);
polygon3=fill([2 4 4 2],[1 1 2 2],'w','FaceALpha',1);
xlim([0 5])
ylim([0 5])
The blue rectangle should cover the red one, why does the overlay appear purple then?
  1 Comment
Image Analyst
Image Analyst on 23 Aug 2014
Good question. I can see why you're puzzled (as am I). You'd think the later blue patch would be in a layer above the red patch and totally cover up the patch underneath since the blue patch is totally opaque. I tried with patch() instead of fill() and got the same thing.

Sign in to comment.

Accepted Answer

Jan
Jan on 23 Aug 2014
Edited: Jan on 24 Aug 2014
The code draws the polygons in the same z==0 plane. The transparency activates the OpenGL renderer. The renderer has to decide the order of patchs along the view direction, but this order is not well defined in OpenGL, because the renderer does not have any information about the order the objects have been defined inside Matlab - in opposite to the Painters renderer.
So try this:
figure
polygon1=fill3([1 3 3 1],[1 1 3 3],[1,1,1,1], 'r','FaceALpha',0.5);
hold on
polygon2=fill3([2 4 4 2],[2 2 4 4],[2,2,2,2], 'b','FaceALpha',1);
polygon3=fill3([2 4 4 2],[1 1 2 2],[3,3,3,3], 'w','FaceALpha',1);
xlim([0 5])
ylim([0 5])
pause(1)
view(2)

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!