2

I would like to make an image like the following: Picture of linear function

But I still have trouble adding the third and fourth graphs into the frame. Could you please help me to set up the right code? Here is my current code:

//linear function...
   settings.outformat="pdf";
//picture will be reduced to half of its size
   size(11cm,0);
   import graph;

   picture pic1,pic2,pic3,pic4;

 //colour
   pen dBlue1=rgb(66/255, 81/255, 172/255);
   pen dBlue2=rgb(42/255, 44/255, 111/255);
   pen dBlack=rgb(16/255, 15/255, 13/255);
   pen dRed=rgb(237/255, 27/255, 43/255);
   pen dGreen=rgb(68/255, 186/255, 59/255);
 // gray sa do svg nekonvertuje spravne, pouzit treba dGray
   pen dGray=rgb(130/255, 130/255, 130/255);

    defaultpen(0.7bp+dGray+ fontsize(14pt));
  // predvolene
    DefaultHead=HookHead;
    pen pblue=1.1bp+dBlue1; 
    pen pgreen=1.1bp+dGreen; 
    pen pred=1.1bp+dRed; 
    pen pblack=1.1bp+dBlack; 


    real as=3bp;    // velkost sipky
    real margin=5mm;

    real xmin = -3;
    real xmax = 5;
    real ymin = -3;
    real ymax = 10;

    xlimits(xmin,xmax);
    ylimits(ymin,ymax);

    //axis and the grid first picture

    xaxis(pic1, Label("$x$",align=2E),NoTicks,Arrow(as));
    yaxis(pic1, Label("$y$",align=2N),NoTicks,Arrow(as));

    // function y=ax+b a>0
    real f(real x) {return 2*x+3; }
    path g = graph(pic1, f,xmin, xmax);
    draw(pic1,g,pred,L= Label("$y=\textrm{a}x+\textrm{b}$", UnFill, 
    position=Relative(0.9), align=SE));     
    
    real f(real x) {return 2*x-3; }
    path g = graph(pic1, f,xmin, xmax);
    draw(pic1,g,pblue,L= Label("$y=\textrm{a}x-\textrm{b}$", UnFill,            
    position=Relative(0.9), align=SE));
    size(pic1,100,100,point(pic1,SW),point(pic1,NE));
    
    frame f1=pic1.fit();
    add(f1);        
    
    // aading second picture
    xaxis(pic2, Label("$x$",align=2E),Arrow(as));
    yaxis(pic2, Label("$y$",align=2N),Arrow(as));

    real f(real x) {return 2*x-1; }
    path g = graph(pic2, f,xmin, xmax);
    draw(pic2,g,pred,
    L= Label("$y=\textrm{a}x+\textrm{b}$", UnFill,          
    position=Relative(0.9), align=SE));     
    
    real f(real x) {return (-2)*x+5; }
    path g = graph(pic2, f,xmin, xmax);
    draw(pic2,g,pblue,
    L= Label("$y=\textrm{-a}x+\textrm{c}$",
    UnFill, position=Relative(0.9), align=SE));
    //draw(arc((1,3),(3,5),),pblack);

    size(pic2,100,100,point(pic2,SW),point(pic2,NE));

    frame f2=pic2.fit();
    f2=shift(max(f1).x-min(f2).x+margin)*f2;
    add(f2);

    // add third picture
    xaxis(pic3, Label("$x$",align=2E),Arrow(as));
    yaxis(pic3, Label("$y$",align=2N),Arrow(as));

    real f(real x) {return 3*x+1; }
    path g = graph(pic3, f,xmin, xmax);
    draw(pic3, g,pgreen,
    L= Label("$y=x+\textrm{b}$", UnFill,            
    position=Relative(0.7), align=SE), Arrows(as)); 
    real f(real x) {return -2*x+1; }
    path g = graph(pic3, f,xmin, xmax);
    draw(pic3, g,pgreen,
    L= Label("$y=\dfrac{1}{3}x+\textrm{b}$", UnFill,    
    position=Relative(0.7), align=SE), Arrows(as)); 
    
    size(pic3,100,100,point(pic3,SW),point(pic3,NE));

    //frame f3=pic3.fit();
    //f3=shift(0,min(f1).y-max(f3).y-margin)*f3;
    //add(f3); 

    \\add 4th picture
    xaxis(pic4, Label("$x$",align=2E),Arrow(as));
    yaxis(pic4, Label("$y$",align=2N),Arrow(as));

    draw(pic4,(3,ymin-0.25)--(3,ymax+0.25),pred,
    L= Label("$x=\textrm{a}$", UnFill,position=Relative(0.9)));
    draw(pic4,(xmin-0.25,2)--(xmax+0.25,2),pblue,
    L= Label("$y=\textrm{b}$",NW));
    dot(pic4,(3,2),pred);

    label(pic4, "[a,b]",(3,3), NE, pblack);

    size(pic4,100,100,point(pic4,SW),point(pic4,NE));

    //frame f4=pic4.fit();
    //f4=shift(max(f3).x-min(f4).x+margin,min(f2).y-max(f4).y-margin)*f4;
    //add(f4);
4
  • 1
    Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem.
    – Sam
    Commented Nov 19, 2020 at 10:20
  • its is compilable by asymptote
    – ewa
    Commented Nov 19, 2020 at 11:56
  • @ewa: it is not compliable, as I have tested on asymptote.ualberta.ca
    – Black Mild
    Commented Nov 22, 2020 at 12:03
  • Now it could be compiliable... I take awway both line codes for last two pictures...there is some problem with the shift. Thank you for any advices
    – ewa
    Commented Nov 23, 2020 at 9:57

1 Answer 1

2

This is a starting point ...

size(11cm);

picture pic1, pic2, pic3, pic4;

draw(pic1,Label("$x$",Relative(0.99)),(0,0)--(5,0),Arrow);
draw(pic1,Label("$y$",Relative(0.99)),(0,0)--(0,5),Arrow);
label(pic1,"Asymptote",(2.5,2.5));
add(pic1);

draw(pic2,Label("$x$",Relative(0.99)),(0,0)--(5,0),Arrow);
draw(pic2,Label("$y$",Relative(0.99)),(0,0)--(0,5),Arrow);
label(pic2,"The Vector",(2.5,2.5),(W+E)/2);
add(shift(8,0)*pic2);

draw(pic3,Label("$x$",Relative(0.99)),(0,0)--(5,0),Arrow);
draw(pic3,Label("$y$",Relative(0.99)),(0,0)--(0,5),Arrow);
label(pic3,"Graphics",(2.5,2.5),(N+S)/2);
add(shift(0,-8)*pic3);

draw(pic4,Label("$x$",Relative(0.99)),(0,0)--(5,0),Arrow);
draw(pic4,Label("$y$",Relative(0.99)),(0,0)--(0,5),Arrow);
label(pic4,"Language",(2.5,2.5),(0,0));
add(shift(8,-8)*pic4);

enter image description here

1
  • Thank you @Nguyen Van Justonly Chi, thats the way how to start.. I was also curios why using xaxis with the size declaration of the frames in the pictures doesn't works. But thanks a lot.
    – ewa
    Commented Nov 24, 2020 at 8:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .