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;
24 public class Plotter extends ApplicationFrame {
29 private static final long serialVersionUID = 5905547086247935278L;
50 public void plot(
double[] times, RealMatrix y, String chartname) {
51 final XYDataset dataset = createDataset(times, y);
52 plot(times, dataset, chartname);
55 public void plot(
double[] times,
double[][] y, String chartname) {
56 final XYDataset dataset = createDataset(times, y);
57 plot(times, dataset, chartname);
60 public void plot(
double[] x,
double[] fx, String chartname) {
61 final XYDataset dataset = createDataset(x, fx);
62 plot(x, dataset, chartname);
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);
73 RefineryUtilities.centerFrameOnScreen(
this);
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));
84 dataset.addSeries(series);
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]);
96 dataset.addSeries(series);
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]);
107 dataset.addSeries(series);
void plot(double[] x, double[] fx, String chartname)
void plot(double[] times, double[][] y, String chartname)
Basic methods for plotting results of dynamical sytem simulations.
Main reduced model class.
Plotter(final String title)
A demonstration application showing how to create a simple time series chart.
void plotResult(double[] times, RealMatrix y, ReducedModel rm)
void plot(double[] times, RealMatrix y, String chartname)
void plotResult(double[] times, double[][] y, ReducedModel rm)