MATLAB: Setting order and transparency in plotyy

alphaareaMATLABplotplotyy

[AX,H1,H2] = plotyy(x1,y1,x2,y2,@plot,@area);
So I plot a line and an area in one chart. Sadly, part of my line is covered by the area and cannot be seen… How to use program to force the line in front of the area and make the area transparent? How to set alpha? Thanks!

Best Answer

You cannot do that with plotyy.
Transparency requires using the OpenGL renderer; none of the other renderers support it. But the OpenGL renderer is defined in such a way that when you have an area (or surface) and a line in the same plane, the order in which they are drawn does not depend upon the order of the commands: OpenGL reorders them as it sees fit. And unfortunately the drivers for some graphics card exactly reverse the proper order, so you cannot count on it always being the same.
When you are using OpenGL, the mechanism you need to use to ensure that one object is in front of the other is to change the relative Z coordinates of the two objects so that they are no longer in the same plane; OpenGL will then use normal "closer object is on top" rules. In order to do that with a line plot, you will have to use plot3() rather than plot(). I do not know at the moment what would be needed to change the Z coordinates of an area plot.