Plot opaque element above transparent object

1 次查看(过去 30 天)
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 个评论
Image Analyst
Image Analyst 2014-8-23
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.

请先登录,再进行评论。

采纳的回答

Jan
Jan 2014-8-23
编辑:Jan 2014-8-24
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)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by