Make transparent contourf plot

조회 수: 10 (최근 30일)
Lukas Bystricky
Lukas Bystricky 2015년 12월 24일
댓글: Walter Roberson 2020년 12월 19일
I'd like to overlay a contourf plot on top of a map of the world. To do this the contourf will need to be transparent. Following the instructions in Steve Lord's answer here I was able to get this to work on a Windows machine (I don't remember the Matlab version number, but it was not 2015). On my home Linux machine running Matlab 2015a, the code snippet from the above answer does not work. No error or warning message, it just does the contour plot and pauses at each step but the plot does not become more transparent.
Is there some issue with OpenGL in Linux that prevents this from working properly?
Edit: Here is the code snippet in question. This works on Windows, but apparently not on Linux.
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
  댓글 수: 2
Walter Roberson
Walter Roberson 2015년 12월 25일
The code appears to work for me on OS-X on R2014a.
Are you using
opengl software
?
Lukas Bystricky
Lukas Bystricky 2015년 12월 25일
I did try that, but that gives the error message:
Error using opengl
Switching to software OpenGL rendering at runtime on unix is not supported.

댓글을 달려면 로그인하십시오.

답변 (2개)

Walter Roberson
Walter Roberson 2015년 12월 25일
R2014b and later generate contour objects that do not have a FaceAlpha property. As yet (R2015b) there is no documented way of controlling the transparency of filled contour objects.
  댓글 수: 2
Lukas Bystricky
Lukas Bystricky 2015년 12월 27일
That's a shame. It's odd that they would remove a feature as part of an upgrade.
Walter Roberson
Walter Roberson 2015년 12월 27일
Contours themselves never had an alpha: they happened to be implemented by something that could be broken apart to use an alpha, but it was not a feature of contours directly.
My understanding is that they are adding in functionality like this as they go. I do not have any information about when it will re-appear.

댓글을 달려면 로그인하십시오.


Michael
Michael 2020년 12월 18일
One work around is to plot a surface and change the view. Here is an example
data = rand(100,100);
surf(data,'EdgeColor','None','Facealpha',0.5);
view([0 90])
  댓글 수: 1
Walter Roberson
Walter Roberson 2020년 12월 19일
I think I remember seeing a way to get alpha in contours in more recent releases, but I would have to investigate further.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by