PageRenderTime 50ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/scalalab281Src/scalaSci/math/plot/PlotPanel.java

https://code.google.com/p/scalalab/
Java | 861 lines | 421 code | 120 blank | 320 comment | 49 complexity | 9f1a2b7597c3a110d4d616fa60744235 MD5 | raw file
  1. package scalaSci.math.plot;
  2. import java.awt.BorderLayout;
  3. import java.awt.Color;
  4. import java.awt.Graphics;
  5. import java.awt.GridLayout;
  6. import java.awt.Image;
  7. import java.awt.image.BufferedImage;
  8. import java.awt.image.RenderedImage;
  9. import java.io.File;
  10. import java.io.IOException;
  11. import java.util.LinkedList;
  12. import javax.imageio.ImageIO;
  13. import javax.swing.ImageIcon;
  14. import javax.swing.JFrame;
  15. import javax.swing.JPanel;
  16. import scalaSci.math.plot.canvas.Plot2DCanvas;
  17. import scalaSci.math.plot.canvas.PlotCanvas;
  18. import scalaSci.math.plot.components.LegendPanel;
  19. import scalaSci.math.plot.components.PlotToolBar;
  20. import scalaSci.math.plot.plotObjects.Axis;
  21. import scalaSci.math.plot.plotObjects.Plotable;
  22. import scalaSci.math.plot.plots.Plot;
  23. public abstract class PlotPanel extends JPanel {
  24. public FrameView holdingFrameView = null; // the FrameView that holds the current plot
  25. private static final long serialVersionUID = 1L;
  26. public PlotToolBar plotToolBar;
  27. public PlotCanvas plotCanvas;
  28. public LegendPanel plotLegend;
  29. public final static String EAST = BorderLayout.EAST;
  30. public final static String SOUTH = BorderLayout.SOUTH;
  31. public final static String NORTH = BorderLayout.NORTH;
  32. public final static String WEST = BorderLayout.WEST;
  33. public final static String INVISIBLE = "INVISIBLE";
  34. public final static String SCATTER = "SCATTER";
  35. public final static String LINE = "LINE";
  36. public final static String BAR = "BAR";
  37. public final static String HISTOGRAM = "HISTOGRAM";
  38. public final static String BOX = "BOX";
  39. public final static String STAIRCASE = "STAIRCASE";
  40. public final static String GRID = "GRID";
  41. public final static Color[] COLORLIST = { Color.BLUE, Color.RED, Color.GREEN, Color.YELLOW, Color.ORANGE, Color.PINK, Color.CYAN, Color.MAGENTA };
  42. // identifiers for x and y axis
  43. public final static int xAxisId = 0;
  44. public final static int yAxisId = 1;
  45. public final static int zAxisId = 2;
  46. static PlotPanel currentPanel;
  47. public PlotPanel(PlotCanvas _canvas, String legendOrientation) {
  48. plotCanvas = _canvas;
  49. setBackground(Color.WHITE);
  50. setLayout(new BorderLayout());
  51. addPlotToolBar(NORTH);
  52. addLegend(legendOrientation);
  53. add(plotCanvas, BorderLayout.CENTER);
  54. setOpaque(false);
  55. }
  56. public PlotPanel(Plot2DPanel [][] panels, String legendOrientation) {
  57. int nPanelsX = panels.length;
  58. int nPanelsY = panels[0].length;
  59. currentPanel = panels[0][0]; // use this panel as the current one
  60. setBackground(Color.WHITE);
  61. JPanel plotsPanel = new JPanel(new GridLayout(nPanelsX, nPanelsY));
  62. for (int x=0; x<nPanelsX; x++)
  63. for (int y=0; y<nPanelsY; y++)
  64. plotsPanel.add(panels[x][y]);
  65. PlotPanel firstPanel = panels[0][0];
  66. plotCanvas = firstPanel.plotCanvas;
  67. setLayout(new BorderLayout());
  68. add(plotsPanel, BorderLayout.CENTER);
  69. setOpaque(false);
  70. }
  71. public PlotPanel(Plot3DPanel [][] panels, String legendOrientation) {
  72. int nCanvasX = panels.length;
  73. int nCanvasY = panels[0].length;
  74. currentPanel = panels[0][0]; // use this panel as the current one
  75. setBackground(Color.WHITE);
  76. JPanel plotsPanel = new JPanel(new GridLayout(nCanvasX, nCanvasY));
  77. for (int x=0; x<nCanvasX; x++)
  78. for (int y=0; y<nCanvasY; y++)
  79. plotsPanel.add(panels[x][y]);
  80. PlotPanel firstPanel = panels[0][0];
  81. plotCanvas = firstPanel.plotCanvas;
  82. setLayout(new BorderLayout());
  83. add(plotsPanel, BorderLayout.CENTER);
  84. setOpaque(false);
  85. }
  86. public PlotPanel(PlotCanvas _canvas) {
  87. this(_canvas, INVISIBLE);
  88. }
  89. /**
  90. * Defines where the legend of the plot should be added to the plot
  91. * panel.
  92. *
  93. * @param location Location where should be put the legend (String).
  94. * location can have the following values (case insensitive): EAST,
  95. * SOUTH, WEST, NORTH, INVISIBLE (legend will be hidden in this case).
  96. * Any other value will be ignored and an error message will be sent to
  97. * the error output.
  98. */
  99. public void addLegend(String location) {
  100. if (location.equalsIgnoreCase(EAST)) {
  101. plotLegend = new LegendPanel(this, LegendPanel.VERTICAL);
  102. add(plotLegend, EAST);
  103. } else if (location.equalsIgnoreCase(SOUTH)) {
  104. plotLegend = new LegendPanel(this, LegendPanel.HORIZONTAL);
  105. add(plotLegend, SOUTH);
  106. } else if (location.equalsIgnoreCase(WEST)) {
  107. plotLegend = new LegendPanel(this, LegendPanel.VERTICAL);
  108. add(plotLegend, WEST);
  109. } else if (location.equalsIgnoreCase(NORTH)) {
  110. plotLegend = new LegendPanel(this, LegendPanel.HORIZONTAL);
  111. add(plotLegend, NORTH);
  112. } else if (location.equalsIgnoreCase(INVISIBLE)) {
  113. plotLegend = new LegendPanel(this, LegendPanel.INVISIBLE);
  114. // add(legends, BorderLayout.NORTH);
  115. } else
  116. System.err.println("Orientation " + location + " is unknonw.");
  117. }
  118. public void addLegend(String location, Plot2DPanel commentedPanel) {
  119. if (location.equalsIgnoreCase(EAST)) {
  120. plotLegend = new LegendPanel(this, LegendPanel.VERTICAL);
  121. commentedPanel.add(plotLegend, EAST);
  122. } else if (location.equalsIgnoreCase(SOUTH)) {
  123. plotLegend = new LegendPanel(this, LegendPanel.HORIZONTAL);
  124. commentedPanel.add(plotLegend, SOUTH);
  125. } else if (location.equalsIgnoreCase(WEST)) {
  126. plotLegend = new LegendPanel(this, LegendPanel.VERTICAL);
  127. add(plotLegend, WEST);
  128. } else if (location.equalsIgnoreCase(NORTH)) {
  129. plotLegend = new LegendPanel(this, LegendPanel.HORIZONTAL);
  130. commentedPanel.add(plotLegend, NORTH);
  131. } else if (location.equalsIgnoreCase(INVISIBLE)) {
  132. plotLegend = new LegendPanel(this, LegendPanel.INVISIBLE);
  133. // add(legends, BorderLayout.NORTH);
  134. } else
  135. System.err.println("Orientation " + location + " is unknonw.");
  136. }
  137. /**
  138. * Removes the current legend from the plot panel.
  139. */
  140. public void removeLegend() {
  141. remove(plotLegend);
  142. }
  143. /**
  144. * Moves the legend to the specified location.
  145. *
  146. * @param location Location where should be put the legend (String).
  147. * location can have the following values (case insensitive): EAST,
  148. * SOUTH, WEST, NORTH, INVISIBLE (legend will be hidden in this case).
  149. * Any other value will be ignored and an error message will be sent to
  150. * the error output.
  151. */
  152. public void setLegendOrientation(String location) {
  153. removeLegend();
  154. addLegend(location);
  155. }
  156. /**
  157. * Adds a new plot toolbar to the specified location. The previous toolbar
  158. * is deleted.
  159. * @param location Location where should be put the toolbar (String).
  160. * location can have the following values (case insensitive): EAST,
  161. * SOUTH, WEST, NORTH.
  162. * Any other value will be ignored and an error message will be sent to
  163. * the error output.
  164. */
  165. public void addPlotToolBar(String location) {
  166. if (location.equalsIgnoreCase(EAST)) {
  167. removePlotToolBar();
  168. plotToolBar = new PlotToolBar(this);
  169. plotToolBar.setFloatable(false);
  170. add(plotToolBar, EAST);
  171. } else if (location.equalsIgnoreCase(SOUTH)) {
  172. removePlotToolBar();
  173. plotToolBar = new PlotToolBar(this);
  174. plotToolBar.setFloatable(false);
  175. add(plotToolBar, SOUTH);
  176. } else if (location.equalsIgnoreCase(WEST)) {
  177. removePlotToolBar();
  178. plotToolBar = new PlotToolBar(this);
  179. plotToolBar.setFloatable(false);
  180. add(plotToolBar, WEST);
  181. } else if (location.equalsIgnoreCase(NORTH)) {
  182. removePlotToolBar();
  183. plotToolBar = new PlotToolBar(this);
  184. plotToolBar.setFloatable(false);
  185. add(plotToolBar, NORTH);
  186. } else
  187. System.err.println("Location " + location + " is unknonw.");
  188. }
  189. public void addPlotToolBar(String location, Plot2DPanel controledPanel) {
  190. if (location.equalsIgnoreCase(EAST)) {
  191. removePlotToolBar();
  192. plotToolBar = new PlotToolBar(controledPanel);
  193. plotToolBar.setFloatable(false);
  194. add(plotToolBar, EAST);
  195. } else if (location.equalsIgnoreCase(SOUTH)) {
  196. removePlotToolBar();
  197. plotToolBar = new PlotToolBar(controledPanel);
  198. plotToolBar.setFloatable(false);
  199. add(plotToolBar, SOUTH);
  200. } else if (location.equalsIgnoreCase(WEST)) {
  201. removePlotToolBar();
  202. plotToolBar = new PlotToolBar(controledPanel);
  203. plotToolBar.setFloatable(false);
  204. add(plotToolBar, WEST);
  205. } else if (location.equalsIgnoreCase(NORTH)) {
  206. removePlotToolBar();
  207. plotToolBar = new PlotToolBar(this);
  208. plotToolBar.setFloatable(false);
  209. add(plotToolBar, NORTH);
  210. } else
  211. System.err.println("Location " + location + " is unknonw.");
  212. }
  213. /**
  214. * Removes the plot toolbar from the panel.
  215. */
  216. public void removePlotToolBar() {
  217. if (plotToolBar == null)
  218. return;
  219. remove(plotToolBar);
  220. }
  221. /**
  222. * Moves the plot toolbar to the specified location.
  223. * @param location Location where should be put the toolbar (String).
  224. * location can have the following values (case insensitive): EAST,
  225. * SOUTH, WEST, NORTH.
  226. * Any other value will be ignored and an error message will be sent to
  227. * the error output.
  228. */
  229. public void setPlotToolBarOrientation(String location) {
  230. addPlotToolBar(location);
  231. }
  232. // ///////////////////////////////////////////
  233. // ////// set actions ////////////////////////
  234. // ///////////////////////////////////////////
  235. public void setActionMode(int am) {
  236. plotCanvas.setActionMode(am);
  237. }
  238. public void setNoteCoords(boolean b) {
  239. plotCanvas.setNoteCoords(b);
  240. }
  241. public void setEditable(boolean b) {
  242. plotCanvas.setEditable(b);
  243. }
  244. public boolean getEditable() {
  245. return plotCanvas.getEditable();
  246. }
  247. public void setNotable(boolean b) {
  248. plotCanvas.setNotable(b);
  249. }
  250. public boolean getNotable() {
  251. return plotCanvas.getNotable();
  252. }
  253. // ///////////////////////////////////////////
  254. // ////// set/get elements ///////////////////
  255. // ///////////////////////////////////////////
  256. public LinkedList<Plot> getPlots() {
  257. return plotCanvas.getPlots();
  258. }
  259. public Plot getPlot(int i) {
  260. return plotCanvas.getPlot(i);
  261. }
  262. public int getPlotIndex(Plot p) {
  263. return plotCanvas.getPlotIndex(p);
  264. }
  265. public LinkedList<Plotable> getPlotables() {
  266. return plotCanvas.getPlotables();
  267. }
  268. public Plotable getPlotable(int i) {
  269. return plotCanvas.getPlotable(i);
  270. }
  271. /**
  272. * Return the axis specified in parameter.
  273. * @param i Axis number. 0 for X, 1 for Y, 2 for Z.
  274. * @return The axis which number is given in parameter.
  275. */
  276. public Axis getAxis(int i) {
  277. return plotCanvas.getGrid().getAxis(i);
  278. }
  279. /**
  280. * Returns the scaling for all of the axis of the plot.
  281. * @return An array of String
  282. *
  283. */
  284. public String[] getAxisScales() {
  285. return plotCanvas.getAxisScales();
  286. }
  287. // TODO axes labels are rested after addPlot... correct this.
  288. /**
  289. * Sets the name of the axis, in this order: X, Y and Z.
  290. * @param labels One to three strings containing the name of each axis.
  291. */
  292. public void setAxisLabels(String... labels) {
  293. plotCanvas.setAxisLabels(labels);
  294. }
  295. /**
  296. * Sets the name of the axis specified in parameter.
  297. * @param axe Axis number. 0 for X, 1 for Y, 2 for Z.
  298. * @param label Name to be given.
  299. */
  300. public void setAxisLabel(int axe, String label) {
  301. plotCanvas.setAxisLabel(axe, label);
  302. }
  303. /**
  304. * Sets the scale of the axes, linear or logarithm, in this order: X,Y,Z.
  305. * @param scales Strings containing the scaling, LOG or LIN (case insensitive) for the axes.
  306. */
  307. public void setAxisScales(String... scales) {
  308. plotCanvas.setAxisScales(scales);
  309. }
  310. /**
  311. * Sets the scaling of the specified axis.
  312. * @param axe Axis number. 0 for X, 1 for Y, 2 for Z.
  313. * @param scale String specifying the scaling. LIN or LOG, case insensitive.
  314. */
  315. public void setAxisScale(int axe, String scale) {
  316. plotCanvas.setAxiScale(axe, scale);
  317. }
  318. /**
  319. * Sets the boundaries for each axis.
  320. * @param min Array of at most 3 doubles specifying the min bound of each axis, in this order: X,Y,Z.
  321. * @param max Array of at most 3 doubles specifying the max bound of each axis, in this order: X,Y,Z.
  322. */
  323. public void setFixedBounds(double[] min, double[] max) {
  324. plotCanvas.setFixedBounds(min, max);
  325. }
  326. /**
  327. * Sets the boundaries for the specified axis.
  328. * @param axe Axis number to modify. 0 for X, 1 for Y, 2 for Z.
  329. * @param min Min bound of the axis.
  330. * @param max Max bound of the axis.
  331. */
  332. public void setFixedBounds(int axe, double min, double max) {
  333. plotCanvas.setFixedBounds(axe, min, max);
  334. }
  335. /**
  336. * Modify bounds of the axes so as to include the point given in parameter.
  337. * @param into Coords of the point to include in bounds.
  338. */
  339. public void includeInBounds(double... into) {
  340. plotCanvas.includeInBounds(into);
  341. }
  342. /**
  343. * Modify axes boundaries so as to include all the points of a given plot.
  344. * @param plot Plot to include.
  345. */
  346. public void includeInBounds(Plot plot) {
  347. plotCanvas.includeInBounds(plot);
  348. }
  349. /**
  350. * Set bounds automatically.
  351. */
  352. public void setAutoBounds() {
  353. plotCanvas.setAutoBounds();
  354. }
  355. /**
  356. * Set bounds automatically for one axis.
  357. * @param axe Number of the axis to modify. 0 for X, 1 for Y, 2 for Z.
  358. */
  359. public void setAutoBounds(int axe) {
  360. plotCanvas.setAutoBounds(axe);
  361. }
  362. public double[][] mapData(Object[][] stringdata) {
  363. return plotCanvas.mapData(stringdata);
  364. }
  365. public void resetMapData() {
  366. plotCanvas.resetMapData();
  367. }
  368. // ///////////////////////////////////////////
  369. // ////// add/remove elements ////////////////
  370. // ///////////////////////////////////////////
  371. public void addLabel(String text, Color c, double... where) {
  372. plotCanvas.addLabel(text, c, where);
  373. }
  374. public void addBaseLabel(String text, Color c, double... where) {
  375. plotCanvas.addBaseLabel(text, c, where);
  376. }
  377. public void addPlotable(Plotable p) {
  378. plotCanvas.addPlotable(p);
  379. }
  380. public void removePlotable(Plotable p) {
  381. plotCanvas.removePlotable(p);
  382. }
  383. public void removePlotable(int i) {
  384. plotCanvas.removePlotable(i);
  385. }
  386. public int addPlot(Plot newPlot) {
  387. return plotCanvas.addPlot(newPlot);
  388. }
  389. protected Color getNewColor() {
  390. return COLORLIST[plot.currentPlotCnt % COLORLIST.length];
  391. }
  392. public int addPlot(String type, String name, double[]... v) {
  393. return addPlot(type, name, getNewColor(), v);
  394. }
  395. public abstract int addPlot(String type, String name, Color c, double[]... v);
  396. public void setPlot(int I, Plot p) {
  397. plotCanvas.setPlot(I, p);
  398. }
  399. public void changePlotData(int I, double[]... XY) {
  400. plotCanvas.changePlotData(I, XY);
  401. }
  402. public void changePlotName(int I, String name) {
  403. plotCanvas.changePlotName(I, name);
  404. }
  405. public void changePlotColor(int I, Color c) {
  406. plotCanvas.changePlotColor(I, c);
  407. }
  408. public void removePlot(int I) {
  409. plotCanvas.removePlot(I);
  410. }
  411. public void removePlot(Plot p) {
  412. plotCanvas.removePlot(p);
  413. }
  414. public void removeAllPlots() {
  415. plotCanvas.removeAllPlots();
  416. }
  417. public void addVectortoPlot(int numPlot, double[][] v) {
  418. plotCanvas.addVectortoPlot(numPlot, v);
  419. }
  420. public int addScalogramPlot(String name, double [][] XY) {
  421. return ((Plot2DCanvas) plotCanvas).addScalogramPlot(name, getNewColor(), XY);
  422. }
  423. public void addQuantiletoPlot(int numPlot, int numAxe, double rate, boolean symetric, double[] q) {
  424. plotCanvas.addQuantiletoPlot(numPlot, numAxe, rate, symetric, q);
  425. }
  426. public void addQuantiletoPlot(int numPlot, int numAxe, double rate, boolean symetric, double q) {
  427. plotCanvas.addQuantiletoPlot(numPlot, numAxe, rate, symetric, q);
  428. }
  429. public void addQuantilestoPlot(int numPlot, int numAxe, double[][] q) {
  430. plotCanvas.addQuantilestoPlot(numPlot, numAxe, q);
  431. }
  432. public void addQuantilestoPlot(int numPlot, int numAxe, double[] q) {
  433. plotCanvas.addQuantilestoPlot(numPlot, numAxe, q);
  434. }
  435. public void addGaussQuantilestoPlot(int numPlot, int numAxe, double[] s) {
  436. plotCanvas.addGaussQuantilestoPlot(numPlot, numAxe, s);
  437. }
  438. public void addGaussQuantilestoPlot(int numPlot, int numAxe, double s) {
  439. plotCanvas.addGaussQuantilestoPlot(numPlot, numAxe, s);
  440. }
  441. public void toGraphicFile(File file) throws IOException {
  442. // otherwise toolbar appears
  443. plotToolBar.setVisible(false);
  444. Image image = createImage(getWidth(), getHeight());
  445. paint(image.getGraphics());
  446. image = new ImageIcon(image).getImage();
  447. BufferedImage bufferedImage = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_RGB);
  448. Graphics g = bufferedImage.createGraphics();
  449. g.drawImage(image, 0, 0, Color.WHITE, null);
  450. g.dispose();
  451. // make it reappear
  452. plotToolBar.setVisible(true);
  453. try {
  454. ImageIO.write((RenderedImage) bufferedImage, "PNG", file);
  455. } catch (IllegalArgumentException ex) {
  456. }
  457. }
  458. /* these methods allow the handling of axis by retrieving first a PlotPanel reference.
  459. t = inc(0, 0.01, 20);
  460. x = sin(0.2*t)+5*cos(0.23*t);;
  461. fig = figure(1); plot(t,y);
  462. fig.xlabel("Time axis t"); */
  463. public void xlabel(String xLabelStr) {
  464. setAxisLabel(scalaSci.math.plot.PlotPanel.xAxisId, xLabelStr);
  465. }
  466. public void ylabel(String yLabelStr) {
  467. setAxisLabel(scalaSci.math.plot.PlotPanel.yAxisId, yLabelStr);
  468. }
  469. public void zlabel(String zLabelStr) {
  470. if (this instanceof Plot3DPanel) {
  471. setAxisLabel(scalaSci.math.plot.PlotPanel.zAxisId, zLabelStr);
  472. }
  473. }
  474. public void title(String titleStr) {
  475. int plotCnt = plot.currentPlotCnt-1;
  476. if (plotCnt < 0 )
  477. plotCnt = 0;
  478. FrameView currentView = plot.allFrames[plotCnt];
  479. if (currentView != null)
  480. currentView.setTitle(titleStr);
  481. }
  482. public static void main(String[] args) {
  483. int n=2; int m=3;
  484. try {
  485. Plot2DPanel [] [] mySubplots = new Plot2DPanel[n][m];
  486. for (int ni=0; ni<n; ni++)
  487. for (int mi=0; mi<m; mi++)
  488. mySubplots[ni][mi] = new Plot2DPanel();
  489. Plot2DPanel mSinePlot = mySubplots[0][0];
  490. int np=2000;
  491. double SF = 0.012;
  492. double [] x = new double [np];
  493. double [] t = new double [np];
  494. for (int k=0; k<np; k++) {
  495. t[k] = SF*k;
  496. x[k] = Math.sin(t[k]);
  497. }
  498. mSinePlot.addLinePlot("Sine Plot", new Color(0, 200, 0), t, x);
  499. Plot2DPanel mTwoSinesPlot = mySubplots[1][1];
  500. double SF2 = 0.018;
  501. double [] y = new double [np];
  502. for (int k=0; k<np; k++) {
  503. y[k] = x[k]+Math.sin(x[k]*SF2*t[k]);
  504. }
  505. mTwoSinesPlot.addLinePlot("Complex Sines Plot", new Color(0, 0, 200), t, y);
  506. mySubplots[1][0].addBarPlot("barplot", new Color(0,50, 50), t, y);
  507. Plot2DPanel p = new Plot2DPanel(mySubplots, PlotPanel.NORTH);
  508. FrameView f = new FrameView(p);
  509. f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
  510. } catch (Exception e) {
  511. e.printStackTrace();
  512. }
  513. try {
  514. Plot3DPanel [] [] mySubplots3D = new Plot3DPanel[m][n];
  515. for (int ni=0; ni<n; ni++)
  516. for (int mi=0; mi<m; mi++)
  517. mySubplots3D[ni][mi] = new Plot3DPanel();
  518. Plot3DPanel mySine3Plot = mySubplots3D[0][0];
  519. int np=2000;
  520. double SF = 0.012;
  521. double [] x = new double [np];
  522. double [] t = new double [np];
  523. double [] y = new double [np];
  524. for (int k=0; k<np; k++) {
  525. t[k] = SF*k;
  526. x[k] = Math.sin(t[k]);
  527. y[k] = x[k] +t[k]*Math.random();
  528. }
  529. mySine3Plot.addLinePlot("Sine3 Plot", new Color(0, 200, 0), t, x, y);
  530. Plot3DPanel p = new Plot3DPanel( mySubplots3D, PlotPanel.NORTH);
  531. FrameView f = new FrameView(p);
  532. f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
  533. } catch (Exception e) {
  534. e.printStackTrace();
  535. }
  536. /* 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"
  537. + "[-l <INVISIBLE|NORTH|SOUTH|EAST|WEST>] giving the legend position\n"
  538. + "[options] are:\n"
  539. + " -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"
  540. + " SCATTER|LINE|BAR: each line of the ASCII file contains coordinates of one point.\n"
  541. + " HISTOGRAM2D(<integer h>): ASCII file contains the 1D sample (i.e. m=1) to split in h slices.\n"
  542. + " 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"
  543. + " 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"
  544. + " 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"
  545. + " 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"
  546. + " -n name name of the plot\n"
  547. + " -v <ASCII file (n,3|2)> vector data to add to the plot\n"
  548. + " -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"
  549. + " -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"
  550. + " -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.";
  551. if (args.length == 0) {
  552. double[][] data = new double[20][];
  553. for (int i = 0; i < data.length; i++)
  554. data[i] = new double[] { Math.random(), Math.random(), Math.random() };
  555. ASCIIFile.writeDoubleArray(new File("tmp.dat"), data);
  556. args = new String[] { "-3D", "-l", "SOUTH", "-t", "SCATTER", "tmp.dat" };
  557. System.out.println(man);
  558. System.out.println("\nExample: jplot.<sh|bat> " + Array.cat(args));
  559. }
  560. PlotPanel p = null;
  561. if (args[0].equals("-2D"))
  562. p = new Plot2DPanel();
  563. else if (args[0].equals("-3D"))
  564. p = new Plot3DPanel();
  565. else
  566. System.out.println(man);
  567. try {
  568. String leg = "INVISIBLE";
  569. String type = SCATTER;
  570. String name = "";
  571. double[][] v = null;
  572. double[] qX = null;
  573. double[] qY = null;
  574. double[] qZ = null;
  575. double qXp = 0;
  576. double qYp = 0;
  577. double qZp = 0;
  578. double[][] qPX = null;
  579. double[][] qPY = null;
  580. double[][] qPZ = null;
  581. double[] qNX = null;
  582. double[] qNY = null;
  583. double[] qNZ = null;
  584. for (int i = 1; i < args.length; i++) {
  585. //System.out.println("<" + args[i] + ">");
  586. if (args[i].equals("-l")) {
  587. leg = args[i + 1];
  588. i++;
  589. } else if (args[i].equals("-t")) {
  590. type = args[i + 1];
  591. i++;
  592. } else if (args[i].equals("-n")) {
  593. name = args[i + 1];
  594. i++;
  595. } else if (args[i].equals("-v")) {
  596. v = ASCIIFile.readDoubleArray(new File(args[i + 1]));
  597. i++;
  598. } else if (args[i].startsWith("-qX(")) {
  599. qX = ASCIIFile.readDouble1DArray(new File(args[i + 1]));
  600. qXp = Double.parseDouble(args[i].substring(4, args[i].length() - 1));
  601. i++;
  602. } else if (args[i].startsWith("-qY(")) {
  603. qY = ASCIIFile.readDouble1DArray(new File(args[i + 1]));
  604. qYp = Double.parseDouble(args[i].substring(4, args[i].length() - 1));
  605. i++;
  606. } else if (args[i].startsWith("-qZ(")) {
  607. qZ = ASCIIFile.readDouble1DArray(new File(args[i + 1]));
  608. qZp = Double.parseDouble(args[i].substring(4, args[i].length() - 1));
  609. i++;
  610. } else if (args[i].equals("-qPX")) {
  611. qPX = ASCIIFile.readDoubleArray(new File(args[i + 1]));
  612. i++;
  613. } else if (args[i].equals("-qPY")) {
  614. qPY = ASCIIFile.readDoubleArray(new File(args[i + 1]));
  615. i++;
  616. } else if (args[i].equals("-qPZ")) {
  617. qPZ = ASCIIFile.readDoubleArray(new File(args[i + 1]));
  618. i++;
  619. } else if (args[i].equals("-qNX")) {
  620. qNX = ASCIIFile.readDouble1DArray(new File(args[i + 1]));
  621. i++;
  622. } else if (args[i].equals("-qNY")) {
  623. qNY = ASCIIFile.readDouble1DArray(new File(args[i + 1]));
  624. i++;
  625. } else if (args[i].equals("-qNZ")) {
  626. qNZ = ASCIIFile.readDouble1DArray(new File(args[i + 1]));
  627. i++;
  628. } else {
  629. File input_file = new File(args[i]);
  630. int n = 0;
  631. if (input_file.exists()) {
  632. if (name.length() == 0)
  633. name = input_file.getName();
  634. if (p instanceof Plot2DPanel) {
  635. Plot2DPanel p2d = (Plot2DPanel) p;
  636. if (type.equals("SCATTER"))
  637. n = p2d.addScatterPlot(name, ASCIIFile.readDoubleArray(input_file));
  638. else if (type.equals("LINE"))
  639. n = p2d.addLinePlot(name, ASCIIFile.readDoubleArray(input_file));
  640. else if (type.equals("BAR"))
  641. n = p2d.addBarPlot(name, ASCIIFile.readDoubleArray(input_file));
  642. else if (type.startsWith("HISTOGRAM2D(")) {
  643. n = p2d
  644. .addHistogramPlot(name, ASCIIFile.readDouble1DArray(input_file), Integer
  645. .parseInt(type.substring(12, type.length() - 1)));
  646. } else if (type.startsWith("CLOUD2D(")) {
  647. n = p2d.addCloudPlot(name, ASCIIFile.readDoubleArray(input_file), Integer.parseInt(type.substring(8, type.indexOf(","))),
  648. Integer.parseInt(type.substring(type.indexOf(",") + 1, type.length() - 1)));
  649. } else
  650. p2d.addPlot(type, name, ASCIIFile.readDoubleArray(input_file));
  651. } else {
  652. Plot3DPanel p3d = (Plot3DPanel) p;
  653. if (type.equals("SCATTER"))
  654. n = p3d.addScatterPlot(name, ASCIIFile.readDoubleArray(input_file));
  655. else if (type.equals("LINE"))
  656. n = p3d.addLinePlot(name, ASCIIFile.readDoubleArray(input_file));
  657. else if (type.equals("BAR"))
  658. n = p3d.addBarPlot(name, ASCIIFile.readDoubleArray(input_file));
  659. else if (type.startsWith("HISTOGRAM3D(")) {
  660. n = p3d.addHistogramPlot(name, ASCIIFile.readDoubleArray(input_file), Integer.parseInt(type.substring(12, type.indexOf(","))),
  661. Integer.parseInt(type.substring(type.indexOf(",") + 1, type.length() - 1)));
  662. } else if (type.equals("GRID3D")) {
  663. n = p3d.addGridPlot(name, ASCIIFile.readDoubleArray(input_file));
  664. } else if (type.startsWith("CLOUD3D(")) {
  665. n = p3d.addCloudPlot(name, ASCIIFile.readDoubleArray(input_file), Integer.parseInt(type.substring(8, type.indexOf(","))),
  666. Integer.parseInt(type.substring(type.indexOf(",") + 1, type.indexOf(",", type.indexOf(",") + 1))), Integer
  667. .parseInt(type.substring(type.indexOf(",", type.indexOf(",") + 1) + 1, type.length() - 1)));
  668. } else
  669. p3d.addPlot(type, name, ASCIIFile.readDoubleArray(input_file));
  670. }
  671. if (v != null)
  672. p.addVectortoPlot(n, v);
  673. if (qX != null)
  674. p.addQuantiletoPlot(n, 0, qXp, false, qX);
  675. if (qY != null)
  676. p.addQuantiletoPlot(n, 1, qYp, false, qY);
  677. if (qZ != null)
  678. p.addQuantiletoPlot(n, 2, qZp, false, qZ);
  679. if (qPX != null)
  680. p.addQuantilestoPlot(n, 0, qPX);
  681. if (qPY != null)
  682. p.addQuantilestoPlot(n, 1, qPY);
  683. if (qPZ != null)
  684. p.addQuantilestoPlot(n, 2, qPZ);
  685. if (qNX != null)
  686. p.addGaussQuantilestoPlot(n, 0, qNX);
  687. if (qNY != null)
  688. p.addGaussQuantilestoPlot(n, 1, qNY);
  689. if (qNZ != null)
  690. p.addGaussQuantilestoPlot(n, 2, qNZ);
  691. type = "SCATTER";
  692. leg = "SOUTH";
  693. name = "";
  694. qX = null;
  695. qY = null;
  696. qZ = null;
  697. qXp = 0;
  698. qYp = 0;
  699. qZp = 0;
  700. v = null;
  701. qPX = null;
  702. qPY = null;
  703. qPZ = null;
  704. qNX = null;
  705. qNY = null;
  706. qNZ = null;
  707. } else {
  708. System.out.println("File " + args[i] + " unknown.");
  709. System.out.println(man);
  710. }
  711. }
  712. }
  713. p.setLegendOrientation(leg);
  714. FrameView f = new FrameView(p);
  715. f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  716. } catch (Exception e) {
  717. e.printStackTrace();
  718. System.err.println("\n" + man);
  719. } */
  720. }
  721. }