JaRMoS  1.1
Java Reduced Model Simulations
 All Classes Namespaces Files Functions Variables Enumerator Groups Pages
Plotter.java
Go to the documentation of this file.
1 package kermor.visual;
2 
4 
5 import org.apache.commons.math.linear.RealMatrix;
6 import org.jfree.chart.ChartFactory;
7 import org.jfree.chart.ChartPanel;
8 import org.jfree.chart.JFreeChart;
9 import org.jfree.chart.plot.PlotOrientation;
10 import org.jfree.data.xy.XYDataset;
11 import org.jfree.data.xy.XYSeries;
12 import org.jfree.data.xy.XYSeriesCollection;
13 import org.jfree.ui.ApplicationFrame;
14 import org.jfree.ui.RefineryUtilities;
15 
24 public class Plotter extends ApplicationFrame {
25 
29  private static final long serialVersionUID = 5905547086247935278L;
30 
37  public Plotter(final String title) {
38  super(title);
39  setVisible(false);
40  }
41 
42  public void plotResult(double[] times, RealMatrix y, ReducedModel rm) {
43  plot(times, y, rm.name);
44  }
45 
46  public void plotResult(double[] times, double[][] y, ReducedModel rm) {
47  plot(times, y, rm.name);
48  }
49 
50  public void plot(double[] times, RealMatrix y, String chartname) {
51  final XYDataset dataset = createDataset(times, y);
52  plot(times, dataset, chartname);
53  }
54 
55  public void plot(double[] times, double[][] y, String chartname) {
56  final XYDataset dataset = createDataset(times, y);
57  plot(times, dataset, chartname);
58  }
59 
60  public void plot(double[] x, double[] fx, String chartname) {
61  final XYDataset dataset = createDataset(x, fx);
62  plot(x, dataset, chartname);
63  }
64 
65  private void plot(double[] xdata, XYDataset y, String chartname) {
66  final JFreeChart chart = ChartFactory.createXYLineChart(chartname, "time t", "outputs y_i", y,
67  PlotOrientation.VERTICAL, false, true, false);
68  final ChartPanel pnl = new ChartPanel(chart);
69  pnl.setPreferredSize(new java.awt.Dimension(500, 270));
70  pnl.setMouseZoomable(true, false);
71  setContentPane(pnl);
72  pack();
73  RefineryUtilities.centerFrameOnScreen(this);
74  setVisible(true);
75  }
76 
77  private XYDataset createDataset(double[] times, RealMatrix y) {
78  XYSeriesCollection dataset = new XYSeriesCollection();
79  for (int i = 0; i < y.getRowDimension(); i++) {
80  XYSeries series = new XYSeries("Dim " + (i + 1));
81  for (int j = 0; j < y.getColumnDimension(); j++) {
82  series.add(times[j], y.getEntry(i, j));
83  }
84  dataset.addSeries(series);
85  }
86  return dataset;
87  }
88 
89  private XYDataset createDataset(double[] times, double[][] y) {
90  XYSeriesCollection dataset = new XYSeriesCollection();
91  for (int i = 0; i < y.length; i++) {
92  XYSeries series = new XYSeries("Dim " + (i + 1));
93  for (int j = 0; j < y[i].length; j++) {
94  series.add(times[j], y[i][j]);
95  }
96  dataset.addSeries(series);
97  }
98  return dataset;
99  }
100 
101  private XYDataset createDataset(double[] x, double[] fx) {
102  XYSeriesCollection dataset = new XYSeriesCollection();
103  XYSeries series = new XYSeries("f(x)");
104  for (int i = 0; i < x.length; i++) {
105  series.add(x[i], fx[i]);
106  }
107  dataset.addSeries(series);
108  return dataset;
109  }
110 }
void plot(double[] x, double[] fx, String chartname)
Definition: Plotter.java:60
void plot(double[] times, double[][] y, String chartname)
Definition: Plotter.java:55
Basic methods for plotting results of dynamical sytem simulations.
Definition: Plotter.java:24
Main reduced model class.
Plotter(final String title)
A demonstration application showing how to create a simple time series chart.
Definition: Plotter.java:37
void plotResult(double[] times, RealMatrix y, ReducedModel rm)
Definition: Plotter.java:42
void plot(double[] times, RealMatrix y, String chartname)
Definition: Plotter.java:50
void plotResult(double[] times, double[][] y, ReducedModel rm)
Definition: Plotter.java:46