manpagez: man pages & more
info mathgl
Home | html | info | man
[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

9.6.8 Ternary plot sample

../png/ternary

C++ code

mglData x(50),y(50),rx(10),ry(10), a(20,30);
a.Modify("4*x*y");
x.Modify("0.25*(1+cos(2*pi*x))");
y.Modify("0.25*(1+sin(2*pi*x))");
rx.Modify("rnd"); ry.Modify("(1-v)*rnd",rx);
gr->Text(mglPoint(-0.8,1.3), "Ternary plot (x+y+t=1)");
gr->Ternary(1);
gr->Plot(x,y,"r2");
gr->Plot(rx,ry,"q^ ");
gr->Cont(a);
gr->Line(mglPoint(0.5,0), mglPoint(0,0.75), "g2");
gr->Axis(); gr->Grid("xyz","B;");
gr->Label('x',"x comp.");
gr->Label('y',"y comp.");
gr->Label('t',"t comp.");

MGL code

new rx 10
new ry 10
new x 50
new y 50
new a 20 30
modify a '4*x*y'
modify x '0.25*(1+cos(2*pi*x))'
modify y '0.25*(1+sin(2*pi*x))'
modify rx 'rnd'
modify ry 'rnd*(1-v)' rx
text -0.8 1.3 'Ternary plot (x+y+t=1)'
ternary 1
plot x y 'r2'
plot rx ry 'q^ '
cont a
line 0.5 0 0 0.75 'g2'
axis
grid 'xyz' 'B;'
xlabel 'x comp.'
ylabel 'y comp.'
tlabel 't comp.'

Pure C code

HMDT x,y,rx,ry,a;
x = mgl_create_data_size(50,1,1);
y = mgl_create_data_size(50,1,1);
rx = mgl_create_data_size(50,1,1);
ry = mgl_create_data_size(50,1,1);
a = mgl_create_data_size(20,30,1);
mgl_data_modify(x,"0.25*(1+cos(2*pi*x))",0);
mgl_data_modify(y,"0.25*(1+sin(2*pi*x))",0);
mgl_data_modify(rx,"rnd",0);
mgl_data_modify_vw(ry,"(1-v)*rnd",rx,0);
mgl_data_modify(a,"4*x*y",0);
mgl_puts_ext(gr,-0.8,1.3,0.,"Ternary plot (x+y+t=1)","C",-1.4,'t');
mgl_set_ternary(gr,1);
mgl_plot_xy(gr,x,y,"r2");
mgl_plot_xy(gr,rx,ry,"q^ ");
mgl_cont(gr,a,"",7,0.);
mgl_line(gr,0.5,0.,0.,0.,0.75,0.,"g2",2);
mgl_axis(gr,"xyz");
mgl_axis_grid(gr,"xyz","B:");
mgl_label(gr,'x',"x comp");
mgl_label(gr,'y',"y comp");
mgl_label(gr,'t',"t comp");
mgl_delete_data(a);
mgl_delete_data(x);     mgl_delete_data(y);
mgl_delete_data(rx);    mgl_delete_data(ry);

Fortran code

integer a,x,y,rx,ry, mgl_create_data_size
x = mgl_create_data_size(50,1,1)
y = mgl_create_data_size(50,1,1)
rx = mgl_create_data_size(50,1,1)
ry = mgl_create_data_size(50,1,1)
a = mgl_create_data_size(20,30,1)
call mgl_data_modify(x,'0.25*(1+cos(2*pi*x))',0)
call mgl_data_modify(y,'0.25*(1+sin(2*pi*x))',0)
call mgl_data_modify(rx,'rnd',0)
call mgl_data_modify_vw(ry,'(1-v)*rnd',rx,rx)
call mgl_data_modify(a,'4*x*y',0)
call mgl_puts_ext(gr,-0.8,1.3,0.,'Ternary plot (x+y+t=1)','C',-1.4,'t')
call mgl_set_ternary(gr,1)
call mgl_plot_xy(gr,x,y,'r2')
call mgl_plot_xy(gr,rx,ry,'q^ ')
call mgl_cont(gr,a,'',7,0.)
call mgl_line(gr,0.5,0.,0.,0.,0.75,0.,'g2',2)
call mgl_axis(gr,'xyz')
call mgl_axis_grid(gr,'xyz','B:')
call mgl_label(gr,'x','x comp')
call mgl_label(gr,'y','y comp')
call mgl_label(gr,'t','t comp')
call mgl_delete_data(a)
call mgl_delete_data(x)
call mgl_delete_data(y)
call mgl_delete_data(rx)
call mgl_delete_data(ry)

Python

x, y, rx, ry, a = mglData(50), mglData(50), mglData(10), mglData(10), mglData(20,30);
a.Modify("4*x*y");
x.Modify("0.25*(1+cos(2*pi*x))");   y.Modify("0.25*(1+sin(2*pi*x))");
rx.Modify("rnd");   ry.Modify("(1-v)*rnd",rx);
gr.Puts(-0.8,1.3,0,"Ternary plot (x+y+t=1)","C",-1.4);
gr.Ternary(1);
gr.Plot(x,y,"r2");  gr.Plot(rx,ry,"q^ ");   gr.Cont(a);
gr.Line(0.5,0,0,0,0.75,0,"g2");
gr.Axis();          gr.Grid("xyz","B;");
gr.Label("x","x comp.");
gr.Label("y","y comp.");
gr.Label("t","t comp.");

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]
© manpagez.com 2000-2024
Individual documents may contain additional copyright information.