Alan Bromborsky - 2024-06-08

I figured it out, the correct call is secondaryY(plt_data, etc. then it works.

If I use the default pic and then plot secondary axis (as in the example in the 2d graphs) everything works fine. If I name the graph say with picture plot_data; and execute all commands with a picture argument set to plt_data and do not try to add the secondary axis every works fine but if I then try to execute the secondary axis code I get the error -

if(!primary.scale.set) abort(noprimary);
^
/usr/local/share/asymptote/graph.asy: 1823.31: Primary axis must be drawn before secondary axis

Here is the code -

void plot()
  {
    real xmin = (real)plot_vars.value("xmin");
    real xmax = (real)plot_vars.value("xmax");
    real ymin = (real)plot_vars.value("ymin");
    real ymax = (real)plot_vars.value("ymax");
    string file_name = plot_vars.value("file_name");

    picture spk_data;
    size(spk_data,800,400,IgnoreAspect);
    scale(spk_data,Log,Linear);

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

    draw(spk_data,graph(spk_data,col_data[0].data,col_data[1].data),black);

    real y= point(S).y-1pt;

    string Xmin = "$"+format("%.0e",true,xmin)+"$";
    string Xmax = "$"+format("%.0e",true,xmax)+"$";

    xtick(spk_data,Label(Xmin),(xmin,y));
    xtick(spk_data,Label(Xmax),(xmax,y));

    xaxis(spk_data,latex_names[0], BottomTop(), Ticks(Label("$%.2f$",black),beginlabel=true, endlabel=true, pTick=.8red, ptick=grey, extend=true));
    yaxis(spk_data,latex_names[1], LeftRight(), RightTicks(pTick=.8red, ptick=grey, extend=true));


    bool flg = true;

    if (flg)
    {
      picture q=secondaryY(new void(picture pic) {
      scale(pic,Log,Linear);
      draw(pic,graph(pic,col_data[0].data,col_data[2].data),red);
      ylimits(pic,-180,180);
      yaxis(pic,latex_names[2],Right,red);
      });
      add(q);
    }

    shipout(file_name,spk_data);
  }
 

Last edit: Alan Bromborsky 2024-06-08