1 package org.jgnuplot; 2 3 /** 4 * This class provides the samefunctionality as gnuplot polar.dem 5 * 6 * Show some of the new polar capabilities. 7 * 8 * @author Pander 9 */ 10 public final class PolarDem { 11 private PolarDem() { 12 } 13 14 public static void gnuplot() { 15 Plot.setGnuplotExecutable("gnuplot"); 16 Plot.setPlotDirectory("/tmp"); 17 18 Plot aPlot = new Plot(); 19 // TODOaPlot.unsetBorder(); 20 aPlot.setClip(); 21 aPlot.setPolar(); 22 aPlot.setXTics("axis nomirror"); 23 aPlot.setYTics("axis nomirror"); 24 aPlot.setSamples("160"); 25 aPlot.addExtra("set zeroaxis"); 26 aPlot.setTRange("0", "2*pi"); 27 aPlot.setTitle("Three circles (with aspect ratio distortion)"); 28 aPlot.pushGraph(new Graph(".5")); 29 aPlot.pushGraph(new Graph("1")); 30 aPlot.pushGraph(new Graph("1.5")); 31 aPlot.setOutput(Terminal.PNG, "test/out/polar-01.png"); 32 try { 33 aPlot.plot(); 34 } 35 catch (Exception e) { 36 System.err.println(e); 37 System.exit(1); 38 } 39 40 aPlot.clear(); 41 aPlot.setKey("box"); 42 aPlot.pushGraph(new Graph("cos(2*t)")); 43 aPlot.setOutput(Terminal.PNG, "test/out/polar-02.png"); 44 try { 45 aPlot.plot(); 46 } 47 catch (Exception e) { 48 System.err.println(e); 49 System.exit(1); 50 } 51 52 aPlot.clear(); 53 aPlot.pushGraph(new Graph("2*sqrt(cos(t))")); 54 aPlot.pushGraph(new Graph("-2*sqrt(cos(t))")); 55 aPlot.setOutput(Terminal.PNG, "test/out/polar-03.png"); 56 try { 57 aPlot.plot(); 58 } 59 catch (Exception e) { 60 System.err.println(e); 61 System.exit(1); 62 } 63 64 aPlot.clear(); 65 aPlot.addExtra("set offsets 0,0,0,0"); 66 aPlot.pushGraph(new Graph("sin(4*t)")); 67 aPlot.pushGraph(new Graph("cos(4*t)")); 68 aPlot.setOutput(Terminal.PNG, "test/out/polar-04.png"); 69 try { 70 aPlot.plot(); 71 } 72 catch (Exception e) { 73 System.err.println(e); 74 System.exit(1); 75 } 76 77 aPlot.clear(); 78 aPlot.setXRange("-5", "5"); 79 aPlot.setYRange("-5", "5"); 80 aPlot.pushGraph(new Graph("t/cos(3*t)")); 81 aPlot.setOutput(Terminal.PNG, "test/out/polar-05.png"); 82 try { 83 aPlot.plot(); 84 } 85 catch (Exception e) { 86 System.err.println(e); 87 System.exit(1); 88 } 89 90 aPlot.clear(); 91 aPlot.setAutoscale(); 92 aPlot.setAutoscaleAfterRanges(); 93 aPlot.pushGraph(new Graph("1-sin(t)")); 94 aPlot.setOutput(Terminal.PNG, "test/out/polar-06.png"); 95 try { 96 aPlot.plot(); 97 } 98 catch (Exception e) { 99 System.err.println(e); 100 System.exit(1); 101 } 102 103 aPlot.clear(); 104 aPlot.setTRange("0", "12*pi"); 105 aPlot.pushGraph(new Graph("2*t")); 106 aPlot.setOutput(Terminal.PNG, "test/out/polar-07.png"); 107 try { 108 aPlot.plot(); 109 } 110 catch (Exception e) { 111 System.err.println(e); 112 System.exit(1); 113 } 114 115 aPlot.clear(); 116 aPlot.addExtra("butterfly(x)=exp(cos(x))-2*cos(4*x)+sin(x/12)**5"); 117 aPlot.setSamples("800"); 118 // This is a big one (many samples), be patient... 119 aPlot.setTitle("Butterfly"); 120 aPlot.unsetKey(); 121 aPlot.pushGraph(new Graph("butterfly(t)")); 122 aPlot.setOutput(Terminal.PNG, "test/out/polar-08.png"); 123 try { 124 aPlot.plot(); 125 } 126 catch (Exception e) { 127 System.err.println(e); 128 System.exit(1); 129 } 130 } 131 }