1 package org.jgnuplot;
    2 
    3 /**
    4  * This class provides the samefunctionality as gnuplot simple.dem
    5  *
    6  * Requires data files "[123].dat" from this directory, so change current
    7  * working directory to this directory before running.
    8  *
    9  * @author Pander
   10  */
   11 public final class SimpleDem {
   12    private SimpleDem() {
   13    }
   14 
   15    public static void gnuplot() {
   16       Plot.setGnuplotExecutable("gnuplot");
   17       Plot.setPlotDirectory("/tmp");
   18 
   19       Plot aPlot = new Plot();
   20       aPlot.setKey("left box");
   21       aPlot.setSamples("50");
   22       aPlot.setRanges("[-10:10]");
   23       aPlot.pushGraph(new Graph("sin(x)"));
   24       aPlot.pushGraph(new Graph("atan(x)"));
   25       aPlot.pushGraph(new Graph("cos(atan(x))"));
   26       aPlot.setOutput(Terminal.PNG, "test/out/simple-01.png");
   27       try {
   28          aPlot.plot();
   29       }
   30       catch (Exception e) {
   31          System.err.println(e);
   32          System.exit(1);
   33       }
   34 
   35       aPlot.clear();
   36       aPlot.setKey("right nobox");
   37       aPlot.setSamples("100");
   38       aPlot.setRanges("[-pi/2:pi]");
   39       aPlot.pushGraph(new Graph("cos(x)"));
   40       aPlot.pushGraph(new Graph("-(sin(x) > sin(x+1) ? sin(x) : sin(x+1))"));
   41       aPlot.setOutput(Terminal.PNG, "test/out/simple-02.png");
   42       try {
   43          aPlot.plot();
   44       }
   45       catch (Exception e) {
   46          System.err.println(e);
   47          System.exit(1);
   48       }
   49 
   50       aPlot.clear();
   51       aPlot.setKey("left box");
   52       aPlot.setSamples("200");
   53       aPlot.setRanges("[-3:5]");
   54       aPlot.pushGraph(new Graph("asin(x)"));
   55       aPlot.pushGraph(new Graph("acos(x)"));
   56       aPlot.setOutput(Terminal.PNG, "test/out/simple-03.png");
   57       try {
   58          aPlot.plot();
   59       }
   60       catch (Exception e) {
   61          System.err.println(e);
   62          System.exit(1);
   63       }
   64 
   65       aPlot.clear();
   66       aPlot.setRanges("[-30:20]");
   67       aPlot.pushGraph(new Graph("besj0(x)*0.12e1", Axes.NOT_SPECIFIED, null,
   68             Style.IMPULSES));
   69       aPlot.pushGraph(new Graph("(x**besj0(x))-2.5", Axes.NOT_SPECIFIED, null,
   70             Style.POINTS));
   71       aPlot.setOutput(Terminal.PNG, "test/out/simple-04.png");
   72       try {
   73          aPlot.plot();
   74       }
   75       catch (Exception e) {
   76          System.err.println(e);
   77          System.exit(1);
   78       }
   79 
   80       aPlot.clear();
   81       aPlot.setSamples("400");
   82       aPlot.setRanges("[-10:10]");
   83       aPlot.pushGraph(new Graph("real(sin(x)**besj0(x))"));
   84       aPlot.setOutput(Terminal.PNG, "test/out/simple-05.png");
   85       try {
   86          aPlot.plot();
   87       }
   88       catch (Exception e) {
   89          System.err.println(e);
   90          System.exit(1);
   91       }
   92 
   93       aPlot.clear();
   94       aPlot.setKey("outside below");
   95       aPlot.setRanges("[-5*pi:5*pi] [-5:5]");
   96       aPlot.pushGraph(new Graph("real(tan(x)/atan(x))"));
   97       aPlot.pushGraph(new Graph("1/x"));
   98       aPlot.setOutput(Terminal.PNG, "test/out/simple-06.png");
   99       try {
  100          aPlot.plot();
  101       }
  102       catch (Exception e) {
  103          System.err.println(e);
  104          System.exit(1);
  105       }
  106 
  107       aPlot.clear();
  108       aPlot.setKey("left box");
  109       aPlot.setAutoscale();
  110       aPlot.setSamples("800");
  111       aPlot.setRanges("[-30:20]");
  112       aPlot.pushGraph(new Graph("sin(x*20)*atan(x)"));
  113       aPlot.setOutput(Terminal.PNG, "test/out/simple-07.png");
  114       try {
  115          aPlot.plot();
  116       }
  117       catch (Exception e) {
  118          System.err.println(e);
  119          System.exit(1);
  120       }
  121 
  122       aPlot.clear();
  123       aPlot.setRanges("[-19:19]");
  124       aPlot.pushGraph(new Graph("1.dat", null, Axes.NOT_SPECIFIED, null,
  125             Style.IMPULSES, LineType.NOT_SPECIFIED, PointType.NOT_SPECIFIED));
  126       aPlot.pushGraph(new Graph("2.dat", null, Axes.NOT_SPECIFIED, null,
  127             Style.NOT_SPECIFIED, LineType.NOT_SPECIFIED,
  128             PointType.NOT_SPECIFIED));
  129       aPlot.pushGraph(new Graph("3.dat", null, Axes.NOT_SPECIFIED, null,
  130             Style.LINES, LineType.NOT_SPECIFIED, PointType.NOT_SPECIFIED));
  131       aPlot.setOutput(Terminal.PNG, "test/out/simple-08.png");
  132       try {
  133          aPlot.plot();
  134       }
  135       catch (Exception e) {
  136          System.err.println(e);
  137          System.exit(1);
  138       }
  139 
  140       aPlot.clear();
  141       aPlot.setRanges("[-19:19]");
  142       aPlot.addExtra("f(x) = x/100");
  143       aPlot.pushGraph(new Graph("1.dat", null, Axes.NOT_SPECIFIED, null,
  144             Style.IMPULSES, LineType.NOT_SPECIFIED, PointType.NOT_SPECIFIED));
  145       aPlot.pushGraph(new Graph("2.dat", null, "thru f(x)", Axes.NOT_SPECIFIED,
  146             null, Style.NOT_SPECIFIED, LineType.NOT_SPECIFIED,
  147             PointType.NOT_SPECIFIED));
  148       aPlot.pushGraph(new Graph("3.dat", null, Axes.NOT_SPECIFIED, null,
  149             Style.LINES, LineType.NOT_SPECIFIED, PointType.NOT_SPECIFIED));
  150       aPlot.setOutput(Terminal.PNG, "test/out/simple-09.png");
  151       try {
  152          aPlot.plot();
  153       }
  154       catch (Exception e) {
  155          System.err.println(e);
  156          System.exit(1);
  157       }
  158    }
  159 }