Setting transparancy of surface plot on Octave

笑着哭i 提交于 2020-01-02 05:42:05

问题


I am running Octave 3.4.0 and want to create a transparent surface plot. However, I have not been able to do so when messing around with facealpha, edgealpha, alphadata and alphadatamapping.

Example code for creating a non-transparent surface:

p = peaks(40);
f1 = figure(10);clf
s1 = surface(p)
view(3)
xlabel('x');ylabel('y');
hold on;plot3([0 40],[40 0],[-10 10],'k')
set(s1,'edgecolor','none')
set(s1,'facealpha',0.2)

The result of this given in the image below. As you can see, the line drawn diagnonlly at the start is hidden behind the surface, even though the surface is suppose to be semi-transparent. Is this a bug in my version of Octave, or have I missed something?


回答1:


This works for me on Octave 3.6.2 using gnuplot as the graphics toolkit. So you better upgrade your Octave installation.

Two things to note though:

  1. the part of the diagonal line that goes behind the surface is not drawn in a lighter so it still looks weird;
  2. with the new experimental fltk graphics toolkit, it doesn't work at all.



回答2:


I agree with Vidar: his code doesn't work with latest Octave 3.8.1 (Cygwin 1.7.30(0.272/5/3) setup_x86_64.exe:2.850 xterm 305-1 Gnuplot 4.6.3-3). facealpha just makes surf of lighter color. One workaround however, is that mesh command in octave has a feature of throwing away the faces: hidden (manual).

So

p = peaks(40);
f1 = figure(10);clf
s1 = mesh(p)
view(3)
xlabel('x');ylabel('y');
hold on;plot3([0 40],[40 0],[-10 10],'k')
hidden('off')

produces




回答3:


This actually worked for me in Octave 5.1.0 but the order of commands is important. You need to set the alpha BEFORE plotting the line. Try just the surface on it's own and play with the alpha - it works:

>> s1 = surface(p)
s1 = -2.7876
>> view(3)
>> set(s1,'facealpha',0.5)
>> colormap jet
>> grid on; % so you can see the grid through the transparent surface:

Surf with transparency



来源:https://stackoverflow.com/questions/12072412/setting-transparancy-of-surface-plot-on-octave

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!