Стиль линии и проблема толщины в scilab
Я пытаюсь построить пять разных сюжетов, каждый из которых состоит из четырех разных линий. Я изменяю стиль и толщину линии, используя код f.children.children(1).children.line_style = 2;
f.children.children(1).children.thickness = 2;
, Работает только на одном участке. В случае подзаговоров это дает ошибку, что размерность не согласована. Вместо своего кода я пишу здесь простой код, который также выдает ту же ошибку. Буду благодарен, если кто-то поможет мне здесь. Код
clear;clc
p = 0:100; t1 = p.^3; t2 = 3*p.^3-5; //functions defined
clf(); f=gcf();
subplot(221);
plot2d(p, t1, 3); //function t1 plotted at (221)
f.children.children(1).children.line_style = 1;
f.children.children(1).children.thickness = 2;
//----------------------------------------------------------------------
plot2d(p, t2, 9); //function t2 plotted with t1 at (221)
f.children.children(1).children.line_style = 2;
f.children.children(1).children.thickness = 2;
//**********************************************************************
x = 1:100; y1 = 2*x-5; y2 = 10*x+100; //functions y1 and y2 defined
subplot(222);
plot2d(x, y1, 6); //function y1 plotted at (222)
f.children.children(1).children.line_style = 1;
f.children.children(1).children.thickness = 2;
//----------------------------------------------------------------------
plot2d(x, y2, 5); //function y2 plotted with y1 at (222)
f.children.children(1).children.line_style = 2;
f.children.children(1).children.thickness = 2;
//**********************************************************************
r = 1:100; z1 = 2*r^2-5; z2 = r.^2; //functions z1 and z2 aredefined
subplot(223)
plot2d(r, z1, 1); //function z1 plotted at (223)
f.children.children(1).children.line_style = 6;
f.children.children(1).children.thickness = 2;
//---------------------------------------------
plot2d(r, z2, 3); //function z2 plotted with z1 at (223)
f.children.children(1).children.line_style = 2;
f.children.children(1).children.thickness = 2;
1 ответ
Решение
Я не понимаю, почему именно с помощью gcf
ваш текущий код не работает. Но я бы использовал gce
чтобы получить последний объект. Я хотел бы ввести функцию, чтобы установить стиль линии и толщину, удаляет много дублирования.
Пример кода
clear;clc
p = 0:100; t1 = p.^3; t2 = 3*p.^3-5; //functions defined
clf(); f=gcf();
function set_my_line_styles(style, thickness)
e = gce();
e.children.line_style = style;
e.children.thickness = thickness;
endfunction
subplot(221);
plot2d(p, t1, 3); //function t1 plotted at (221)
set_my_line_styles(1,2);
//----------------------------------------------------------------------
plot2d(p, t2, 9); //function t2 plotted with t1 at (221)
set_my_line_styles(2,2);
//**********************************************************************
x = 1:100; y1 = 2*x-5; y2 = 10*x+100; //functions y1 and y2 defined
subplot(222);
plot2d(x, y1, 6); //function y1 plotted at (222)
set_my_line_styles(1,2);
//----------------------------------------------------------------------
plot2d(x, y2, 5); //function y2 plotted with y1 at (222)
set_my_line_styles(2,2);
//**********************************************************************
r = 1:100; z1 = 2*r^2-5; z2 = r.^2; //functions z1 and z2 aredefined
subplot(223)
plot2d(r, z1, 1); //function z1 plotted at (223)
set_my_line_styles(6,2);
//---------------------------------------------
plot2d(r, z2, 3); //function z2 plotted with z1 at (223)
set_my_line_styles(2,2);