设置log yscale时copyobj legend和facealpha问题

时间:2016-05-20 11:53:37

标签: matlab legend figure

我有以下代码来绘制图片:

%scamp data
[flipedBV, flipeddepth] = flipit(depthi, BVsurf_int_ens);

i=linspace(0,5,100);
edges_eps=10.^(-i); 
logedg_BV= log10(fliplr(edges_eps)); 

[n_BV,xout_BV] = histc(histazza(log10(flipedBV)), logedg_BV);

x = logedg_BV;

%model data
[n_BVn,xout_BVn] = histc(histazza(log10(sqrt(-BVsurf_Num_ens))), logedg_BV);

BVsurfF = figure;hold on
h=area(x,n_BV/sum(n_BV),'facecolor',[1 0 0]);  %%red area where the problem gonna be

legend('SCAMP')
xlabel('$$ N~[1/s]$$','Interpreter','latex','fontsize',18)
set(gca,'fontsize',14,'ygrid','on')
alpha(.5)  %%translucency of the red area

%%add new data
addLineToFig('KEPflu', [0 0 1], BVsurfF, 'BVsurf_Num_ens', logedg_BV);

addLineToFig('KEPflu2', [0 1 1], BVsurfF, 'BVsurf_Num_ens', logedg_BV);

addLineToFig('GASflu', [0 0 0], BVsurfF, 'BVsurf_Num_ens', logedg_BV);

addLineToFig('GASflu2', [1 0 1 ], BVsurfF, 'BVsurf_Num_ens', logedg_BV);

addLineToFig('EPSmin', [1 1 0], BVsurfF, 'BVsurf_Num_ens', logedg_BV);

addLineToFig('GASmin', [.5 .5 0], BVsurfF, 'BVsurf_Num_ens', logedg_BV);

addLineToFig('canuto', [.5 .5 .5]', BVsurfF, 'BVsurf_Num_ens', logedg_BV);

子例程addLineToFig包含在:

function addLineToFig(name, ccol, fighandle, variab, x)%, flippo, depthi)

cd(['E:\SIMULATIONS\',name,'\COMPARED\ensamble']);
load([name,'_ensamble'], variab);


[n_BVn, xout_BVn] = histc(histazza(log10(sqrt(-BVsurf_Num_ens))), x); %%new data

figure(fighandle)

[LEGHbv,OBJHbv,OUTHbv,OUTMbv] = legend; 
P=plot(x,n_BVn/sum(n_BVn),'color',ccol,'linewidth',2); %%plot new data
legend([OUTHbv;P],OUTMbv{:},name) %%update legend

end

基本上,我创建了红色区域的图表,然后使用addLineToFig添加数据并正确获取:

enter image description here

当我尝试复制数字时出现问题:

h1=gcf;
h2=figure;  
objects=allchild(h1);
copyobj(get(h1,'children'),h2);
set(gca,'yscale','log')

enter image description here

正如您所看到的,红色分布的半透明度并未重复,且图例存在一些问题。

问题似乎是我将yscale设置为log的最后一行。如果我评论它代码工作正常。有没有人知道解决方法?

最小代码

i=linspace(0,5,100);
edges_eps=10.^(-i); 
logedg_BV= log10(fliplr(edges_eps)); 

a = 1e-5;
b = 1e-2;
r = (b-a).*rand(1000,1) + a;


[n_BV,xout_BV] = histc(histazza(log10(r)), logedg_BV);

x = logedg_BV;

%model data
r2 = (b-a).*rand(1000,1) + a;
[n_BVn,xout_BVn] = histc(histazza(log10(r2)), logedg_BV);

BVsurfF = figure;hold on
h=area(x,n_BV/sum(n_BV),'facecolor',[1 0 0]);  %%red area where the problem gonna be

legend('SCAMP')
xlabel('$$ N~[1/s]$$','Interpreter','latex','fontsize',18)
set(gca,'fontsize',14,'ygrid','on')
alpha(.5)  %%translucency of the red area

%%add new data
r3 = (b-a).*randn(1000,1) + a;
[n_BVn,xout_BVn] = histc(histazza(log10(r3)), logedg_BV);

figure(BVsurfF) 
[LEGHbv,OBJHbv,OUTHbv,OUTMbv] = legend;
P=plot(x,n_BVn/sum(n_BVn),'color','k','linewidth',2);
legend([OUTHbv;P],OUTMbv{:},'data2')

%%add new data
r4 = (b-a).*rand(1000,1) + a;
[n_BVn,xout_BVn] = histc(histazza(log10(r4)), logedg_BV);

figure(BVsurfF) 
[LEGHbv,OBJHbv,OUTHbv,OUTMbv] = legend;
P=plot(x,n_BVn/sum(n_BVn),'color','y','linewidth',2);
legend([OUTHbv;P],OUTMbv{:},'data3')




h1=gcf;
h2=figure;  
objects=allchild(h1);
copyobj(get(h1,'children'),h2);

1 个答案:

答案 0 :(得分:0)

我通过将原始图形的渲染器设置为' OpenGL'来解决了这个问题:

set(BVsurfF,'renderer','OpenGL')