Menu

Labeling and positioning axes

Help
2022-02-05
2022-02-06
  • Alan Bromborsky

    Alan Bromborsky - 2022-02-05

    I have not been able to label the y-axis tick at ymin. Also I have not been able to locate the x-axis at y=0. I have set the flags in xaxis and yaxis that should let me do this to no effect. I am soliciting any suggestions. Run attached file to see problem in lower graph.

    Also of interest should be my function to label axis using pi fractions useful for axis in radian units.

     
  • John Bowman

    John Bowman - 2022-02-05

    Here's how to make ymin=0 in the gain graph:

    ylimits(gain,0,1);
    
    xaxis(gain,"$\wB$",BottomTop,LeftTicks);
    yaxis(gain,"$\abs{\bfrac{\gfct{\wB}}{\gfct{1}}}$",LeftRight,RightTicks(trailingzero));
    
     
    • Alan Bromborsky

      Alan Bromborsky - 2022-02-06

      The problem is in the phase (bottom) graph.

       

      Last edit: John Bowman 2022-02-06
  • John Bowman

    John Bowman - 2022-02-06

    Similarly, try:

    ylimits(phase,-pi,pi);
    
    yaxis(phase,"$\fct{\phi}{\bfrac{\gfct{\wB}}{\gfct{1}}}$",LeftRight,LT);
    xaxis(phase,"$\wB$",xmin=0.8,xmax=1.2,LeftTicks);
    
     
  • John Bowman

    John Bowman - 2022-02-06

    If you download the latest version of https://raw.githubusercontent.com/vectorgraphics/asymptote/HEAD/base/rational.asy
    you can greatly simplify pilabel:

    import graph;
    import math;
    import rational;
    typedef real realfcn(real);
    typedef string strfcn(real);
    
    texpreamble("\usepackage{bm}");
    texpreamble("\newcommand{\wB}{\bar{\omega}}");
    texpreamble("\newcommand{\lp}{\left (}");
    texpreamble("\newcommand{\rp}{\right )}");
    texpreamble("\newcommand{\fct}[2]{{#1}\lp {#2} \rp}");
    texpreamble("\newcommand{\gfct}[1]{\fct{G}{#1}}");
    texpreamble("\newcommand{\bfrac}[2]{\displaystyle{\frac{#1}{#2}}}");
    texpreamble("\newcommand{\abs}[1]{\left | {#1} \right |}");
    
    typedef string intop(real);
    
    intop pilabel=new string(real x)
    {
        rational r=(rational) (x/pi);
    
        if(r == 0) {return "$0$";}
        if(r == 1) {return "$\pi$";}
        if(r == -1) {return "$-\pi$";}
    
        return math("\displaystyle "+texstring(r)+"\pi");
    };
    
    realfcn Gain(real G1)
    {
      return new real(real w)
      {
        real G = (w/G1)/sqrt((1.0-w**2)**2+(w/G1)**2);
        return G;
      };
    }
    
    real [] g1={10,50,100};
    real margin=5mm;
    
    realfcn Phase(real G1)
    {
      return new real(real w)
      {
        real Ph = atan2(1.0-w**2,-w/G1);
        return Ph;
      };
    }
    
    picture gain;
    scale(gain,Linear,Linear);
    
    for ( int i = 0; i < g1.length; ++i)
    {
      string s = "$\gfct{1} = "+(string) g1[i]+"$";
      draw(gain,graph(gain,Gain(g1[i]),0.8,1.2,n=10000),Pen(i),s);
    }
    
    xaxis(gain,"$\wB$",BottomTop,LeftTicks);
    yaxis(gain,"$\abs{\bfrac{\gfct{\wB}}{\gfct{1}}}$",LeftRight,RightTicks(trailingzero));
    
    //attach(gain,legend(2),(point(S).x,truepoint(S).y),10S,UnFill);
    
    size(gain,300,300,point(gain,SW),point(gain,NE));
    frame f1=bbox(gain,20.0,p=nullpen);
    add(f1);
    
    picture phase;
    scale(phase,Linear,Linear);
    
    for ( int i = 0; i < g1.length; ++i)
    {
      string s = "$\gfct{1} = "+(string) g1[i]+"$";
      draw(phase,graph(phase,Phase(g1[i]),0.8,1.2,n=10000),Pen(i),s);
    }
    
    ticks PiTicks(int n, real ymin, real ymax)
    {
        real [] yi;
        real dy = ymax-ymin;
        int ndy = n * (int) (dy/pi);
        if (ndy*pi-dy < 0.0) ++ndy;
        if (ymin*ymax < 0.0) ++ndy;
        dy = dy/(real) (ndy-1);
        for (int i=0;i<ndy;++i)
        {
            yi.push(ymin+i*dy);
        }
        return LeftTicks(ticklabel=pilabel,beginlabel=true,endlabel=true,yi);
    }
    
    ticks LT = PiTicks(4,-pi,pi);
    
    ylimits(phase,-pi,pi);
    
    yaxis(phase,"$\fct{\phi}{\bfrac{\gfct{\wB}}{\gfct{1}}}$",LeftRight,LT);
    xaxis(phase,"$\wB$",xmin=0.8,xmax=1.2,LeftTicks);
    
    //attach(phase,legend(2),(point(S).x,truepoint(S).y),10S,UnFill);
    
    size(phase,300,300,point(phase,SW),point(phase,NE));
    
    frame f2=bbox(phase,20.0,p=nullpen);
    f2=shift(0,min(f2).y-max(f2).y)*f2;
    //f2=shift(0.0,-200.0)*f2;
    add(f2);
    
     
    • Alan Bromborsky

      Alan Bromborsky - 2022-02-06

      First, thank you for the simplified code, great software, and
      maintaining the software.  I proselytize Asymptote every chance I get.

      I would also like to proselytize something else to that might be of
      interest to you, Geometric Algebra.  The most relevant reference would
      be the book "Geometric Algebra for Computer Science" -

      https://geometricalgebra.org/

      http://geometry.mrao.cam.ac.uk/2005/01/applications-of-conformal-geometric-algebra-in-computer-vision-and-graphics/

      One of the strong points of geometric algebra is that it simplifies
      calculating rotations in n-dimensions-

      https://www.mrao.cam.ac.uk/~clifford/introduction/intro/node9.html

      Then one can use the conformal geometric algebra to perform both
      translations and rotations in 3-dimensions with pure rotations in
      5-dimensions.  Also calculating the intersections of lines, planes, and
      spheres in 3-dimensions is greatly simplified -

      https://en.wikipedia.org/wiki/Conformal_geometric_algebra

      Keep up the great work.

      On 2/6/22 1:28 AM, John Bowman wrote:

      If you download the latest version of
      https://raw.githubusercontent.com/vectorgraphics/asymptote/HEAD/base/rational.asy
      you can greatly simplify pilabel:

      import graph;
      import math;
      import rational;
      typedef real realfcn(real);
      typedef string strfcn(real);

      texpreamble("\usepackage{bm}");
      texpreamble("\newcommand{\wB}{\bar{\omega}}");
      texpreamble("\newcommand{\lp}{\left (}");
      texpreamble("\newcommand{\rp}{\right )}");
      texpreamble("\newcommand{\fct}[2]\lp {#2} \rp}");
      texpreamble("\newcommand{\gfct}[1]{#1}}");
      texpreamble("\newcommand{\bfrac}[2]{#2}}}");
      texpreamble("\newcommand{\abs}[1] \right |}");

      typedef string intop(real);

      intop pilabel=new string(real x)
      {
      rational r=(rational) (x/pi);

       if(r  ==  0)  {return  "$0$";}
       if(r  ==  1)  {return  "$\pi$";}
       if(r  ==  -1)  {return  "$-\pi$";}
      
       return  math("\displaystyle "+texstring(r)+"\pi");
      

      };

      realfcn Gain(real G1)
      {
      return new real(real w)
      {
      real G = (w/G1)/sqrt((1.0-w2)2+(w/G1)**2);
      return G;
      };
      }

      real [] g1={10,50,100};
      real margin=5mm;

      realfcn Phase(real G1)
      {
      return new real(real w)
      {
      real Ph = atan2(1.0-w**2,-w/G1);
      return Ph;
      };
      }

      picture gain;
      scale(gain,Linear,Linear);

      for ( int i = 0; i < g1.length; ++i)
      {
      string s = "$\gfct{1}= "+(string) g1[i]+"$";
      draw(gain,graph(gain,Gain(g1[i]),0.8,1.2,n=10000),Pen(i),s);
      }

      xaxis(gain,"$\wB$",BottomTop,LeftTicks);
      yaxis(gain,"$\abs{\bfrac{\gfct{\wB}}{\gfct{1}}}$",LeftRight,RightTicks(trailingzero));

      //attach(gain,legend(2),(point(S).x,truepoint(S).y),10S,UnFill);

      size(gain,300,300,point(gain,SW),point(gain,NE));
      frame f1=bbox(gain,20.0,p=nullpen);
      add(f1);

      picture phase;
      scale(phase,Linear,Linear);

      for ( int i = 0; i < g1.length; ++i)
      {
      string s = "$\gfct{1}= "+(string) g1[i]+"$";
      draw(phase,graph(phase,Phase(g1[i]),0.8,1.2,n=10000),Pen(i),s);
      }

      ticks PiTicks(int n, real ymin, real ymax)
      {
      real [] yi;
      real dy = ymax-ymin;
      int ndy = n * (int) (dy/pi);
      if (ndypi-dy < 0.0) ++ndy;
      if (ymin
      ymax < 0.0) ++ndy;
      dy = dy/(real) (ndy-1);
      for (int i=0;i<ndy;++i)
      {
      yi.push(ymin+i*dy);
      }
      return LeftTicks(ticklabel=pilabel,beginlabel=true,endlabel=true,yi);
      }

      ticks LT = PiTicks(4,-pi,pi);

      ylimits(phase,-pi,pi);

      yaxis(phase,"$\fct{\phi}{\bfrac{\gfct{\wB}}{\gfct{1}}}$",LeftRight,LT);
      xaxis(phase,"$\wB$",xmin=0.8,xmax=1.2,LeftTicks);

      //attach(phase,legend(2),(point(S).x,truepoint(S).y),10S,UnFill);

      size(phase,300,300,point(phase,SW),point(phase,NE));

      frame f2=bbox(phase,20.0,p=nullpen);
      f2=shift(0,min(f2).y-max(f2).y)f2;
      //f2=shift(0.0,-200.0)
      f2;
      add(f2);


      Labeling and positioning axes
      https://sourceforge.net/p/asymptote/discussion/409349/thread/d74025af41/?limit=25#6906


      Sent from sourceforge.net because you indicated interest in
      https://sourceforge.net/p/asymptote/discussion/409349/

      To unsubscribe from further messages, please visit
      https://sourceforge.net/auth/subscriptions/

       

Log in to post a comment.