2017-04-21 38 views
0

我想用xfpoly生成边界并使用xs2pdf保存它们。然后,我想在这些边界中显示2个函数的图形,为这些函数添加图例并再次保存图像。Scilab - Legend只适用于一组特定的功能

我的代码如下...

clear; clc; xdel(winsid());  

t = -2:0.01:2; 
x_1 = t.^2; x_2 = t.^4; 

xfpoly([-3 -2 -2 -3], [0 0 16 16], color('grey')); 
ax = gca(); 
ax.auto_clear = 'off'; ax.data_bounds = [-3, 0; 3, 3]; 
ax.box = 'on'; 
ax.axes_visible = ['on','on','off']; ax.tight_limits = ['on','on','off']; 
xfpoly([2 3 3 2], [0 0 16 16], color('grey')); 
xfpoly([-1 1 1 -1], [1 1 16 16], color('grey')); 

xs2pdf(gcf(), 'fig_1'); 

plot2d(t, [x_1', x_2'], [color('green'), color('red')]); 
legend(['t^2'; 't^4']); 
leg_ent = gce(); 
leg_ent.text = ['';'';'';'t^2'; 't^4'] 

xs2pdf(gcf(), 'fig_2'); 

回答

0

Atilla's answer给我带来了使用pause命令该解决方案:

clear; clc; xdel(winsid());  

t = -2:0.01:2; 
x_1 = t.^2; x_2 = t.^4; 

plot2d(t, [x_1', x_2'], [color('green'), color('red')]); plot_1 = gce(); 
legend(['t^2'; 't^4']); leg_1 = gce(); 
plot_1.visible = 'off'; leg_1.visible = 'off'; 

xfpoly([-3 -2 -2 -3], [0 0 16 16], color('grey')); 
xfpoly([2 3 3 2], [0 0 16 16], color('grey')); 
xfpoly([-1 1 1 -1], [1 1 16 16], color('grey')); 
ax = gca(); 
ax.box = 'on'; 

xs2pdf(gcf(), 'fig_1'); 
// pause 
plot_1.visible = 'on'; leg_1.visible = 'on'; 
xs2pdf(gcf(), 'fig_2'); 
+0

如果我的回答对你有帮助,你可以赞扬它。我很高兴我能提供帮助。 – Attila

+0

我喜欢upvote。但是我的名声太低,不能这样做...... – ska109

0

你要这样呢?

clear; 
clc; 

t = -2:0.01:2; 
x_1 = t.^2; x_2 = t.^4; 

scf(0); 
clf(0); 
//plot the curves first to make legend easier 
plot2d(t, [x_1', x_2'], [color('green'), color('red')]); 
legend(['t^2'; 't^4']); //the first two elements are the curves, so no neet to modify 
ax = gca(); 
ax.auto_clear = 'off'; 
ax.data_bounds = [-3, 0; 3, 3]; 
ax.box = 'on'; 

xfpoly([-3 -2 -2 -3], [0 0 3 3], color('grey')); 
xfpoly([2 3 3 2], [0 0 3 3], color('grey')); 
xfpoly([-1 1 1 -1], [1 1 3 3], color('grey')); 


scf(1); 
clf(1); 
xfpoly([-3 -2 -2 -3], [0 0 3 3], color('grey')); //ymax sholud be 3, not 16 
xfpoly([2 3 3 2], [0 0 3 3], color('grey')); 
xfpoly([-1 1 1 -1], [1 1 3 3], color('grey')); 
ax = gca(); 
ax.auto_clear = 'off'; 
ax.data_bounds = [-3, 0; 3, 3]; 
ax.box = 'on'; 
+0

是的,我需要创造那些2所绘出。但是(为了教学目的)按照我的问题编写 - 首先是灰色边界,然后添加2条曲线。问题是,我首先创建了5个带有边界的图形,然后在每个图形中添加了5条2条曲线。 – ska109