Menu

gnuplotting from within a TeXmacs Reduce session

Help
2021-07-01
2021-10-03
  • Tilda A. Steiner

    I'm currently working with Reduce (Free PSL version, revision 5595), 17-Jan-2021) from within a TeXmax (2.1) Reduce session on OSX 13.7.

    Symbolic and numerical calculations work fine. So does gnuplotting by using the plot(...)-command. However, when I want to call gnuplot directly, e.g.

    load_package gnuplot;
    on trplot;
    gnuplot(set,polar);
    gnuplot(set,noparametric);
    gnuplot(plot,x*sin x);
    plotshow;
    

    I get the following error message:

    exit
    if(strstrt(GPVAL_TERMINALS,"aqua")!=0)set terminal aqua;else set term x11;
    if(strstrt(GPVAL_TERMINALS,"aqua")!=0)set terminal aqua;else set term x11;
     if(strstrt(GPVAL_TERMINALS,"aqua")!=0)set terminal aqua;else set term x11;
    

    Neither x11 terminal nor the aqua terminal are openend, and nothing else seems to happen.

    What went wrong here? Gnuplot (5.4.2) is installed (MacPorts 2.7.1) and in PATH. Why do direct calls of gnuplot not work? What do I need to be doing to get direct calls of gnuplot going?

    Tilda

     
  • arpi

    arpi - 2021-07-01

    I can confirm the same result on Linux (Ubuntu 20.04 LTS), with Reduce CSL rev. 5758. Same result after each command, except the exit, no plot window.

     
  • Rainer Schöpf

    Rainer Schöpf - 2021-07-01

    For polar plots the dummy variable is t, not x. Try

    gnuplot(plot,t*sin t);
    

    or

    gnuplot(set,dummy,x);
    

    as third line.

    I'll update the manual.

    Rainer

     
  • Tilda A. Steiner

    Thanks for the fast reply, Rainer. That really solved the problem.

    Tilda

     
  • Rainer Schöpf

    Rainer Schöpf - 2021-07-02

    You're welcome. I guess that gnuplot changed its defaults at some point in the past. Another example is that "set noparametric" is deprecated in favour of "unset parametric".

    Rainer

     
  • arpi

    arpi - 2021-07-02

    Thank you, Rainer, for the clarification. I would also like to ask a question concerning the error messages: it shows that reduce always sets aqua or x11 as terminal type. I tried
    gnuplot(set, term, wxt);
    on linux, and it had no effect. Am I doing something wrong, or is it only possible to use x11?

     
  • Rainer Schöpf

    Rainer Schöpf - 2021-07-02

    These are not error messages: these are the commands to set the terminal that are sent to gnuplot, shown because the trplot switch is set to on. You can change them by setting the symoblic mode variable gnuplot_select_terminal!*, e.g. to use the wxt terminal:

    symbolic (gnuplot_select_terminal!* := "if(strstrt(GPVAL_TERMINALS,""aqua"")!=0)set terminal aqua;else set term wxt;");
    

    Commands sent via the Reduce gnuplot command are not shown for some reason.

    Rainer

     
  • Tilda A. Steiner

    I have some questions on direct gnuplot-calls in general and some on specific calls in particular.

    • Does the Reduce interface to gnuplot allow for any gnuplot command or just a subset?
    • Where can I find more information on the syntax beyond the gnuplot section in the manual?

    Some calls seems to be working straight, others produce error messages, e.g when running

    load_package gnuplot;
    plotreset;
    on trplot;
    gnuplot(set,isosamples 40);
    gnuplot(set,xrange [-2:2]
            );
    gnuplot(set,yrange [-2:2]
            );
    gnuplot(splot,exp(-(x^2+y^2))*cos(x/4)*sin(y)*cos(2*(x^2+y^2))
            );
    plotshow;
    

    I get the following:

    Declare isosamples operator ?  (Y or N)
    Type Y or N
    
    uplot(set,xrange[-2$$$:2]);
    at line 7
    ***** Improper delimiter 
    
    gnuplot(set,yrange[-2$$$:2]);
    at line 7
    ***** Improper delimiter 
    

    So what would be the correct delimiter for the gnuplot(set,xrange)command. And is it possible to effectively set gnuplot(set,isosamples 40) and gnuplot(set,samples 40) as well as titles via gnuplot(set,title "Exponential Function") which all don' seem to be working as desired.

    Tilda

     
  • Rainer Schöpf

    Rainer Schöpf - 2021-07-05

    The gnuplot command behaaves like every other Reduce command, i.e. if you write isosamples 40 it is evaluated.
    Try this:

    load_package gnuplot;
    gnuplot(set,isosamples,40);
    gnuplot(set,xrange,"[-2:2]");
    gnuplot(set,yrange,"[-2:2]");
    gnuplot(splot,exp(-(x^2+y^2))*cos(x/4)*sin(y)*cos(2*(x^2+y^2)));
    plotshow;
    

    Rainer

     
  • Tilda A. Steiner

    Thanks for the clarification, Rainer. You 've been a tremendous help! For those on the forum interested in further enhancements may just try this one:

    load_package gnuplot;
    plotreset;
    gnuplot(set,isosamples,96);
    gnuplot(set,samples,96);
    gnuplot(set,xrange,"[-2:2]");
    gnuplot(set,yrange,"[-2:2]");
    gnuplot(set,view,"45,135");
    gnuplot(set,hidden3d);
    gnuplot(set,pm3d);
    gnuplot(set,key,"off");
    gnuplot(set,xyplane,"at -0.6");
    gnuplot(set,title,"""Exponential Function""");
    gnuplot(splot,exp(-(x^2+y^2))*cos(x/4)*sin(y)*cos(2*(x^2+y^2)));
    plotshow;
    

    Cheers
    Tilda

     
  • Rainer Schöpf

    Rainer Schöpf - 2021-07-14

    But that is using nearly none of the Reduce facilities, since it passes the function to plot to gnuplot.

    Try this:

    plot(exp(-(x^2+y^2))*cos(x/4)*sin(y)*cos(2*(x^2+y^2)),title="Exponential Function",hidden3d,pm3d,x=(-2 .. 2)/96,y=(-2 .. 2)/96,view="45,135");
    

    Rainer

     
  • Tilda A. Steiner

    Thanks for the hints, Rainer. I've tried them and they work fine. Yet, your answer raises some questions.

    1. Are the x=(-2 .. 2)/96 and y=(-2 .. 2)/96 instructions in your code equivalent to gnuplot(set,isosamples,96); or gnuplot(set,samples,96); or both in mine?
    2. How would you rewrite gnuplot(set,xyplane,"at -0.6"); in your code ?
    3. Why do you suggest letting Reduce do the as much work as possible. Is it because it can evaluate (more demanding) functions better than gnuplot?
    4. Why has the plot form your code the x-axis shifted by 90 deg clockwise compared to mine? Differently put, your code yields the same results as stand-alone gnuplot; direct calls of gnuplot from within Reduce don't, even though the instruction are equivalent.

    Cheers
    Tilda

     
    • Rainer Schöpf

      Rainer Schöpf - 2021-09-13

      Sorry for the delay in responding. I needed to look at the plot/gnuplot code in Reduce and check a couple of examples before answering, but have been busy with other things.

      1. Both are roughly equivalent, but the mechanism is different. When you use the Reduce plot command, Reduce computes the grid points, writes them to a data file and displays that using gnuplot. My example above translates into these gnuplot commands:
      set term x11
      unset hidden3d
      unset pm3d
      set view 60,30,1,1
      set size 1,1
      set xlabel "y"
      set ylabel "x"
      set zlabel "z"
      set title "REDUCE Plot"
      unset contour
      unset polar
      set parametric
      set view 45,135
      set pm3d
      set hidden3d
      set title "Exponential Function"
      unset key
      splot '/tmp/rainer.plotdt1' with lines
      
      1. There is no equivalent way to specify the xyplane in the plot command. If there is interest, I can add this option, e.g. as xyplane="at -0.6"

      2. If you use only the gnuplot command, why do you need Reduce? You can type in the very same commands into gnuplot directly. On the other hand, you are limited to the functions that gnuplot understands.

      3. I think that set parametric causes the different view.

      Regards,
      Rainer

       
      • Tilda A. Steiner

        Dear Rainer, thank you for your helpful comments. Implementing an xyplane option would be a nice feature to have.

        Tilda

         

Log in to post a comment.