Grid, Ticks and drawing

Help
2011-12-08
2013-05-30
  • Mads Hansen

    Mads Hansen - 2011-12-08

    Hi,
    I'm drawing a grid for my graph, and was wondering if there was an array is automatically made that contains the tick positions?, also when I draw a grid (with the draw(…) command), the lines are drawn on top of the axes, which is unfortunate since the grid is grey and the axes are black, and it seems changing the order of what is drawn "first" does not matter.

    thanks, Mads

     
  • Anonymous

    Anonymous - 2011-12-08

    You forgot to post your example.

     
  • Mads Hansen

    Mads Hansen - 2011-12-08

    Doh :) here is it..

    import graph;
    usepackage("siunitx");
    size(6cm,4cm,IgnoreAspect);
    real xmin = -0.5;
    real xmax = 85;
    real ymax = 12;
    real ymin = -0.5;

    file in=input("nikkel.data");
    real a=in.dimension(0,0).line();
    real f(real t) {return 0.040584301*t + 7.6625177812;}
    a = transpose(a);
    pen dotstyle = black;
    real x=a;
    real y=a;
    real xgrid={12.5,25,37.5,50,62.5,75};
    real ygrid={2.5,5,7.5,10};
    pen gridstyle = dashed + gray(0.75)+linewidth(0.25);

    draw(graph(f,xmin,xmax), black);
    for(int i=0; i<6; ++i){
    draw((xgrid_,ymax)-(xgrid,0),gridstyle);
    }

    for (int i=0; i<4; ++i){
    draw((xmin,ygrid)-(xmax,ygrid), gridstyle);
    }

    for (int i=0; i<13; ++i) {
    dot((x,y),dotstyle);
    }
    xaxis("$T/\si{\celsius}$",xmin,xmax,RightTicks(NoZero),Arrow(3));
    yaxis("$R/\si{\ohm}$",ymin,ymax,LeftTicks(NoZero, step=5,n=2),Arrow(3)); _

     
  • gk-v

    gk-v - 2011-12-08

    when I draw a grid (with the draw(…) command), the lines are drawn on top of the axes, which is unfortunate since the grid is grey and the axes are black, and it seems changing the order of what is drawn "first" does not matter.

    Use "above=true":

    xaxis("$T/\si{\celsius}$",xmin,xmax,RightTicks(NoZero),Arrow(3),above=true);
    yaxis("$R/\si{\ohm}$",ymin,ymax,LeftTicks(NoZero, step=5,n=2),Arrow(3),above=true);
    
     
  • Mads Hansen

    Mads Hansen - 2011-12-08

    Thanks that did it. Did you know if there was a built in variable that held the tick numbers?

     
  • gk-v

    gk-v - 2011-12-08

    Did you know if there was a built in variable that held the tick numbers?

    Something like this:

    size(200);
    import graph;
    real[] TsTicks={1};
    real[] Tsticks={1/4,1/3,1/2,2/3};
    draw((0,0)--(1,1));
    xaxis("$x$"
        , Ticks(Ticks=TsTicks, ticks=Tsticks
                , ticklabel=new string(real x){return string(x);} 
               )
      , above=true
    );
    

    ?

     
  • Mads Hansen

    Mads Hansen - 2011-12-08

    I was thinking about when asymptote generates the ticks automatically, an array with whatever ticks was being used would be very usefull so it wouldn't be neccesary to manually define where the grid lines so each time the ticks change. In the example above, I have to define gridx and gridy manually - It would be easier if there was someway of getting the information without having to look at the (compiled) graph first.

     
  • John Bowman

    John Bowman - 2011-12-11

    You could create create your own tickmodifier (see the definition of OmitTickIntervals in http://asymptote.svn.sourceforge.net/viewvc/asymptote/trunk/asymptote/base/graph.asy).

    Or overload this routine:

    // Automatic tick construction routine.
    ticks Ticks(int sign, Label F="", ticklabel ticklabel=null,
                bool beginlabel=true, bool endlabel=true,
                int N, int n=0, real Step=0, real step=0,
                bool begin=true, bool end=true, tickmodifier modify=None,
                real Size=0, real size=0, bool extend=false,
                pen pTick=nullpen, pen ptick=nullpen)
    {
      return new void(frame f, transform T, Label L, pair side, path g, path g2,
                      pen p, arrowbar arrow, margin margin, ticklocate locate,
                      int[] divisor, bool opposite) {
        real limit=Step == 0 ? axiscoverage*arclength(T*g) : 0;
        tickvalues values=modify(generateticks(sign,F,ticklabel,N,n,Step,step,
                                               Size,size,T,side,g,
                                               limit,p,locate,divisor,opposite));
        Ticks(sign,F,ticklabel,beginlabel,endlabel,values.major,values.minor,
              values.N,begin,end,Size,size,extend,pTick,ptick)
          (f,T,L,side,g,g2,p,arrow,margin,locate,divisor,opposite);
      };
    }
    
     
  • Mads Hansen

    Mads Hansen - 2011-12-13

    Thanks, will have a hard look at it.

     

Log in to post a comment.