I am trying to plot five different subplots and each subplot is consist of four different lines. I am changing line style and thickness using the code f.children.children(1).children.line_style = 2;
f.children.children(1).children.thickness = 2;
. It works only in one plot. In case of subplots it gives error that the dimension are not consistent. Instead of my code I am writing here a simple code which also gives the same error. Will be thankful if someone help me here. The code is
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;
I do not understand exactly why through using gcf
your current code fails. But I would use gce
to get the last entity.
I would introduce a function to set the line style and thickness, removes lots of duplication.
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);