2017-04-21 66 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