public static void main(String[] args) { Plot2DPanel p2 = new Plot2DPanel(); double[][] XYZ = new double[100][2]; for (int j = 0; j < XYZ.length; j++) { XYZ[j][0] = 2 * Math.PI * (double) j / XYZ.length; XYZ[j][1] = Math.sin(XYZ[j][0]); } double[][] XYZ2 = new double[100][2]; for (int j = 0; j < XYZ2.length; j++) { XYZ2[j][0] = 2 * Math.PI * (double) j / XYZ.length; XYZ2[j][1] = Math.sin(2 * XYZ2[j][0]); } p2.addLinePlot("sin", Color.RED, AbstractDrawer.DOTTED_LINE, XYZ); p2.setBackground(new Color(200, 0, 0)); p2.addLinePlot("sin2", Color.BLUE, AbstractDrawer.CROSS_DOT, XYZ2); p2.setLegendOrientation(PlotPanel.SOUTH); new FrameView(p2).setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); Plot3DPanel p = new Plot3DPanel(); XYZ = new double[100][3]; for (int j = 0; j < XYZ.length; j++) { XYZ[j][0] = 2 * Math.PI * (double) j / XYZ.length; XYZ[j][1] = Math.sin(XYZ[j][0]); XYZ[j][2] = Math.sin(XYZ[j][0]) * Math.cos(XYZ[j][1]); } p.addLinePlot("toto", XYZ); p.setLegendOrientation(PlotPanel.SOUTH); new FrameView(p).setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); }
public static void main(String[] args) { Plot2DPanel p = new Plot2DPanel(); double[] X = new double[10]; double[] Y = new double[10]; for (int j = 0; j < X.length; j++) { X[j] = j; Y[j] = Math.random(); } p.addStaircasePlot("toto", X, Y); new FrameView(p).setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Color[] c = new Color[10]; p = new Plot2DPanel(); X = new double[10]; Y = new double[10]; for (int j = 0; j < X.length; j++) { X[j] = j; Y[j] = Math.random(); c[j] = new Color((int) (Math.random() * 0x1000000)); } p.addStaircasePlot("toto", c, X, Y); new FrameView(p).setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }
public static void main(String[] args) { double[] X = new double[500]; for (int i = 0; i < X.length; i++) { X[i] = Math.random() + Math.random(); } Plot2DPanel p = new Plot2DPanel("SOUTH"); p.addHistogramPlot("test", X, 10); new FrameView(p); }
/** * @param myList * <p>Plots values of a List in a line plot. */ public static void simplePlot(List<Double> myList) { // We have to convert the list to array double[] myArray = listToArray(myList); Plot2DPanel plot = new Plot2DPanel(); plot.addLinePlot("my plot", myArray); JFrame frame = new JFrame("a plot panel"); frame.setSize(100, 100); // test frame.setContentPane(plot); frame.setVisible(true); }
/** * @param myList1 * @param myList2 * <p>Plots values of myList1 and myList2 as two separate lines in the same plot. */ public static void twoLinePlot(List<Double> myList1, List<Double> myList2) { // We have to convert the list to array double[] myArray1 = listToArray(myList1); double[] myArray2 = listToArray(myList2); Plot2DPanel plot = new Plot2DPanel(); plot.addLinePlot("my plot", myArray1); plot.addLinePlot("my plot", myArray2); JFrame frame = new JFrame("a plot panel"); frame.setContentPane(plot); frame.setVisible(true); }
public void addLegend(String location, Plot2DPanel commentedPanel) { if (location.equalsIgnoreCase(EAST)) { plotLegend = new LegendPanel(this, LegendPanel.VERTICAL); commentedPanel.add(plotLegend, EAST); } else if (location.equalsIgnoreCase(SOUTH)) { plotLegend = new LegendPanel(this, LegendPanel.HORIZONTAL); commentedPanel.add(plotLegend, SOUTH); } else if (location.equalsIgnoreCase(WEST)) { plotLegend = new LegendPanel(this, LegendPanel.VERTICAL); add(plotLegend, WEST); } else if (location.equalsIgnoreCase(NORTH)) { plotLegend = new LegendPanel(this, LegendPanel.HORIZONTAL); commentedPanel.add(plotLegend, NORTH); } else if (location.equalsIgnoreCase(INVISIBLE)) { plotLegend = new LegendPanel(this, LegendPanel.INVISIBLE); // add(legends, BorderLayout.NORTH); } else System.err.println("Orientation " + location + " is unknown."); }
public static void main(String[] args) { int n = 2; int m = 3; try { Plot2DPanel[][] mySubplots = new Plot2DPanel[n][m]; for (int ni = 0; ni < n; ni++) for (int mi = 0; mi < m; mi++) mySubplots[ni][mi] = new Plot2DPanel(); Plot2DPanel mSinePlot = mySubplots[0][0]; int np = 2000; double SF = 0.012; double[] x = new double[np]; double[] t = new double[np]; for (int k = 0; k < np; k++) { t[k] = SF * k; x[k] = Math.sin(t[k]); } mSinePlot.addLinePlot("Sine Plot", new Color(0, 200, 0), t, x); Plot2DPanel mTwoSinesPlot = mySubplots[1][1]; double SF2 = 0.018; double[] y = new double[np]; for (int k = 0; k < np; k++) { y[k] = x[k] + Math.sin(x[k] * SF2 * t[k]); } mTwoSinesPlot.addLinePlot("Complex Sines Plot", new Color(0, 0, 200), t, y); mySubplots[1][0].addBarPlot("barplot", new Color(0, 50, 50), t, y); Plot2DPanel p = new Plot2DPanel(mySubplots, PlotPanel.NORTH); FrameView f = new FrameView(p); f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); } catch (Exception e) { e.printStackTrace(); } try { Plot3DPanel[][] mySubplots3D = new Plot3DPanel[m][n]; for (int ni = 0; ni < n; ni++) for (int mi = 0; mi < m; mi++) mySubplots3D[ni][mi] = new Plot3DPanel(); Plot3DPanel mySine3Plot = mySubplots3D[0][0]; int np = 2000; double SF = 0.012; double[] x = new double[np]; double[] t = new double[np]; double[] y = new double[np]; for (int k = 0; k < np; k++) { t[k] = SF * k; x[k] = Math.sin(t[k]); y[k] = x[k] + t[k] * Math.random(); } mySine3Plot.addLinePlot("Sine3 Plot", new Color(0, 200, 0), t, x, y); Plot3DPanel p = new Plot3DPanel(mySubplots3D, PlotPanel.NORTH); FrameView f = new FrameView(p); f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); } catch (Exception e) { e.printStackTrace(); } /* String man = "Usage: jplot.<sh|bat> <-2D|-3D> [-l <INVISIBLE|NORTH|SOUTH|EAST|WEST>] [options] <ASCII file (n rows, m columns)> [[options] other ASCII file]\n" + "[-l <INVISIBLE|NORTH|SOUTH|EAST|WEST>] giving the legend position\n" + "[options] are:\n" + " -t <SCATTER|LINE|BAR|HISTOGRAM2D(<integer h>)|HISTOGRAM3D(<integer h>,<integer k>)|GRID3D|CLOUD2D(<integer h>,<integer k>)|CLOUD3D(<integer h>,<integer k>,<integer l>)> type of the plot\n" + " SCATTER|LINE|BAR: each line of the ASCII file contains coordinates of one point.\n" + " HISTOGRAM2D(<integer h>): ASCII file contains the 1D sample (i.e. m=1) to split in h slices.\n" + " HISTOGRAM3D(<integer h>,<integer k>): ASCII file contains the 2D sample (i.e. m=2) to split in h*k slices (h slices on X axis and k slices on Y axis).\n" + " GRID3D: ASCII file is a matrix, first row gives n X grid values, first column gives m Y grid values, other values are Z values.\n" + " CLOUD2D(<integer h>,<integer k>): ASCII file contains the 2D sample (i.e. m=2) to split in h*k slices (h slices on X axis and k slices on Y axis), density of cloud corresponds to frequency of X-Y slice in given 2D sample.\n" + " CLOUD3D(<integer h>,<integer k>,<integer l>): ASCII file contains the 3D sample (i.e. m=3) to split in h*k*l slices (h slices on X axis, k slices on Y axis, l slices on Y axis), density of cloud corresponds to frequency of X-Y-Z slice in given 3D sample.\n" + " -n name name of the plot\n" + " -v <ASCII file (n,3|2)> vector data to add to the plot\n" + " -q<X|Y|Z>(<float Q>) <ASCII file (n,1)> Q-quantile to add to the plot on <X|Y|Z> axis. Each line of the given ASCII file contains the value of quantile for probvability Q.\n" + " -qP<X|Y|Z> <ASCII file (n,p)> p-quantiles density to add to the plot on <X|Y|Z> axis. Each line of the given ASCII file contains p values.\n" + " -qN<X|Y|Z> <ASCII file (n,1)> Gaussian density to add to the plot on <X|Y|Z> axis. Each line of the given ASCII file contains a standard deviation."; if (args.length == 0) { double[][] data = new double[20][]; for (int i = 0; i < data.length; i++) data[i] = new double[] { Math.random(), Math.random(), Math.random() }; ASCIIFile.writeDoubleArray(new File("tmp.dat"), data); args = new String[] { "-3D", "-l", "SOUTH", "-t", "SCATTER", "tmp.dat" }; System.out.println(man); System.out.println("\nExample: jplot.<sh|bat> " + Array.cat(args)); } PlotPanel p = null; if (args[0].equals("-2D")) p = new Plot2DPanel(); else if (args[0].equals("-3D")) p = new Plot3DPanel(); else System.out.println(man); try { String leg = "INVISIBLE"; String type = SCATTER; String name = ""; double[][] v = null; double[] qX = null; double[] qY = null; double[] qZ = null; double qXp = 0; double qYp = 0; double qZp = 0; double[][] qPX = null; double[][] qPY = null; double[][] qPZ = null; double[] qNX = null; double[] qNY = null; double[] qNZ = null; for (int i = 1; i < args.length; i++) { //System.out.println("<" + args[i] + ">"); if (args[i].equals("-l")) { leg = args[i + 1]; i++; } else if (args[i].equals("-t")) { type = args[i + 1]; i++; } else if (args[i].equals("-n")) { name = args[i + 1]; i++; } else if (args[i].equals("-v")) { v = ASCIIFile.readDoubleArray(new File(args[i + 1])); i++; } else if (args[i].startsWith("-qX(")) { qX = ASCIIFile.readDouble1DArray(new File(args[i + 1])); qXp = Double.parseDouble(args[i].substring(4, args[i].length() - 1)); i++; } else if (args[i].startsWith("-qY(")) { qY = ASCIIFile.readDouble1DArray(new File(args[i + 1])); qYp = Double.parseDouble(args[i].substring(4, args[i].length() - 1)); i++; } else if (args[i].startsWith("-qZ(")) { qZ = ASCIIFile.readDouble1DArray(new File(args[i + 1])); qZp = Double.parseDouble(args[i].substring(4, args[i].length() - 1)); i++; } else if (args[i].equals("-qPX")) { qPX = ASCIIFile.readDoubleArray(new File(args[i + 1])); i++; } else if (args[i].equals("-qPY")) { qPY = ASCIIFile.readDoubleArray(new File(args[i + 1])); i++; } else if (args[i].equals("-qPZ")) { qPZ = ASCIIFile.readDoubleArray(new File(args[i + 1])); i++; } else if (args[i].equals("-qNX")) { qNX = ASCIIFile.readDouble1DArray(new File(args[i + 1])); i++; } else if (args[i].equals("-qNY")) { qNY = ASCIIFile.readDouble1DArray(new File(args[i + 1])); i++; } else if (args[i].equals("-qNZ")) { qNZ = ASCIIFile.readDouble1DArray(new File(args[i + 1])); i++; } else { File input_file = new File(args[i]); int n = 0; if (input_file.exists()) { if (name.length() == 0) name = input_file.getName(); if (p instanceof Plot2DPanel) { Plot2DPanel p2d = (Plot2DPanel) p; if (type.equals("SCATTER")) n = p2d.addScatterPlot(name, ASCIIFile.readDoubleArray(input_file)); else if (type.equals("LINE")) n = p2d.addLinePlot(name, ASCIIFile.readDoubleArray(input_file)); else if (type.equals("BAR")) n = p2d.addBarPlot(name, ASCIIFile.readDoubleArray(input_file)); else if (type.startsWith("HISTOGRAM2D(")) { n = p2d .addHistogramPlot(name, ASCIIFile.readDouble1DArray(input_file), Integer .parseInt(type.substring(12, type.length() - 1))); } else if (type.startsWith("CLOUD2D(")) { n = p2d.addCloudPlot(name, ASCIIFile.readDoubleArray(input_file), Integer.parseInt(type.substring(8, type.indexOf(","))), Integer.parseInt(type.substring(type.indexOf(",") + 1, type.length() - 1))); } else p2d.addPlot(type, name, ASCIIFile.readDoubleArray(input_file)); } else { Plot3DPanel p3d = (Plot3DPanel) p; if (type.equals("SCATTER")) n = p3d.addScatterPlot(name, ASCIIFile.readDoubleArray(input_file)); else if (type.equals("LINE")) n = p3d.addLinePlot(name, ASCIIFile.readDoubleArray(input_file)); else if (type.equals("BAR")) n = p3d.addBarPlot(name, ASCIIFile.readDoubleArray(input_file)); else if (type.startsWith("HISTOGRAM3D(")) { n = p3d.addHistogramPlot(name, ASCIIFile.readDoubleArray(input_file), Integer.parseInt(type.substring(12, type.indexOf(","))), Integer.parseInt(type.substring(type.indexOf(",") + 1, type.length() - 1))); } else if (type.equals("GRID3D")) { n = p3d.addGridPlot(name, ASCIIFile.readDoubleArray(input_file)); } else if (type.startsWith("CLOUD3D(")) { n = p3d.addCloudPlot(name, ASCIIFile.readDoubleArray(input_file), Integer.parseInt(type.substring(8, type.indexOf(","))), Integer.parseInt(type.substring(type.indexOf(",") + 1, type.indexOf(",", type.indexOf(",") + 1))), Integer .parseInt(type.substring(type.indexOf(",", type.indexOf(",") + 1) + 1, type.length() - 1))); } else p3d.addPlot(type, name, ASCIIFile.readDoubleArray(input_file)); } if (v != null) p.addVectortoPlot(n, v); if (qX != null) p.addQuantiletoPlot(n, 0, qXp, false, qX); if (qY != null) p.addQuantiletoPlot(n, 1, qYp, false, qY); if (qZ != null) p.addQuantiletoPlot(n, 2, qZp, false, qZ); if (qPX != null) p.addQuantilestoPlot(n, 0, qPX); if (qPY != null) p.addQuantilestoPlot(n, 1, qPY); if (qPZ != null) p.addQuantilestoPlot(n, 2, qPZ); if (qNX != null) p.addGaussQuantilestoPlot(n, 0, qNX); if (qNY != null) p.addGaussQuantilestoPlot(n, 1, qNY); if (qNZ != null) p.addGaussQuantilestoPlot(n, 2, qNZ); type = "SCATTER"; leg = "SOUTH"; name = ""; qX = null; qY = null; qZ = null; qXp = 0; qYp = 0; qZp = 0; v = null; qPX = null; qPY = null; qPZ = null; qNX = null; qNY = null; qNZ = null; } else { System.out.println("File " + args[i] + " unknown."); System.out.println(man); } } } p.setLegendOrientation(leg); FrameView f = new FrameView(p); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } catch (Exception e) { e.printStackTrace(); System.err.println("\n" + man); } */ }