我试图绘制五个不同的子图,每个子图由四个不同的线组成。我正在使用代码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;
答案 0 :(得分:0)
我不明白为什么通过使用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);