[Swift-commit] r4187 - in usertools/plotter: samples/dual src/plotter
noreply at svn.ci.uchicago.edu
noreply at svn.ci.uchicago.edu
Mon Mar 14 23:48:23 CDT 2011
Author: wozniak
Date: 2011-03-14 23:48:23 -0500 (Mon, 14 Mar 2011)
New Revision: 4187
Modified:
usertools/plotter/samples/dual/plot.cfg
usertools/plotter/samples/dual/set2.data
usertools/plotter/src/plotter/Dual.java
Log:
Two data sets, two axes
Modified: usertools/plotter/samples/dual/plot.cfg
===================================================================
--- usertools/plotter/samples/dual/plot.cfg 2011-03-15 03:57:11 UTC (rev 4186)
+++ usertools/plotter/samples/dual/plot.cfg 2011-03-15 04:48:23 UTC (rev 4187)
@@ -1,3 +1,4 @@
+
title = Sample
xlabel = Input
@@ -4,6 +5,11 @@
ylabel1 = Output
ylabel2 = Secondary
+ymin1 = -10
+ymax1 = 30
+ymin2 = -10
+ymax2 = 300
+
label.set1.data = Set 1
label.set2.data = Set 2
Modified: usertools/plotter/samples/dual/set2.data
===================================================================
--- usertools/plotter/samples/dual/set2.data 2011-03-15 03:57:11 UTC (rev 4186)
+++ usertools/plotter/samples/dual/set2.data 2011-03-15 04:48:23 UTC (rev 4187)
@@ -1,2 +1,2 @@
0 -1
-4 3
+4 300
Modified: usertools/plotter/src/plotter/Dual.java
===================================================================
--- usertools/plotter/src/plotter/Dual.java 2011-03-15 03:57:11 UTC (rev 4186)
+++ usertools/plotter/src/plotter/Dual.java 2011-03-15 04:48:23 UTC (rev 4187)
@@ -18,6 +18,7 @@
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.data.Range;
import org.jfree.data.general.Series;
+import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
/**
@@ -36,9 +37,12 @@
// null indicates the value was not set by the user
static Double xmin = null;
static Double xmax = null;
- static Double ymin = null;
- static Double ymax = null;
+ static Double ymin1 = null;
+ static Double ymax1 = null;
+ static Double ymin2 = null;
+ static Double ymax2 = null;
+
/**
Generate simple plot
@param collection The x,y data
@@ -48,7 +52,7 @@
@param ylabel2 Y label text
@param output EPS filename
*/
- public static boolean plot(XYSeriesCollection collection,
+ public static boolean plot(XYSeriesCollection[] collections,
String title, String xlabel,
String ylabel1, String ylabel2,
String output)
@@ -82,10 +86,10 @@
JFreeChart chart =
ChartFactory.createXYLineChart
- (title, xlabel, ylabel1, collection,
+ (title, xlabel, ylabel1, collections[0],
PlotOrientation.VERTICAL, withLegend, false, false);
- setupPlot(chart, collection, ylabel2);
+ setupPlot(chart, collections, ylabel1, ylabel2);
chart.draw(g2d, rectangle);
try
@@ -104,34 +108,41 @@
}
private static void setupPlot(JFreeChart chart,
- XYSeriesCollection collection,
- String ylabel2)
+ XYSeriesCollection[] collections,
+ String ylabel1, String ylabel2)
{
XYPlot plot = chart.getXYPlot();
- XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
+ XYLineAndShapeRenderer renderer1 = new XYLineAndShapeRenderer();
+ XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer();
+
int count = plot.getSeriesCount();
- if (count != 2)
- Util.fatal("dual plot must have two data sets!");
if (bw)
for (int i = 0; i < count; i++)
- renderer.setSeriesPaint(i, Color.BLACK);
- Series series1 = collection.getSeries(0);
+ {
+ renderer1.setSeriesPaint(i, Color.BLACK);
+ renderer2.setSeriesPaint(i, Color.BLACK);
+ }
+ Series series1 = collections[0].getSeries(0);
if (! showShape(series1.getDescription()))
- renderer.setSeriesShapesVisible(0, false);
- Series series2 = collection.getSeries(1);
+ renderer1.setSeriesShapesVisible(0, false);
+ Series series2 = collections[1].getSeries(0);
if (! showShape(series2.getDescription()))
- renderer.setSeriesShapesVisible(1, false);
+ renderer2.setSeriesShapesVisible(1, false);
Plots.setupLegend(chart, properties);
- setAxes(plot, ylabel2);
- plot.setRenderer(renderer);
+ setAxes(plot, ylabel1, ylabel2, collections[1]);
+ plot.setRenderer(0, renderer1);
+ plot.setRenderer(1, renderer2);
plot.setBackgroundPaint(Color.WHITE);
}
- static void setAxes(XYPlot plot, String ylabel2)
+ static void setAxes(XYPlot plot, String ylabel1, String ylabel2,
+ XYSeriesCollection collection)
{
+ plot.setDataset(1, collection);
+
// Actual values: modify if necessary
- double axmin, axmax, aymin, aymax;
+ double axmin, axmax, aymin1, aymax1, aymin2, aymax2;
if (xmin != null || xmax != null)
{
@@ -146,23 +157,38 @@
}
// Left Y axis
- if (ymin != null || ymax != null)
+ if (ymin1 != null || ymax1 != null)
{
- NumberAxis axis = new NumberAxis();
+ NumberAxis axis = new NumberAxis(ylabel1);
plot.setRangeAxis(0, axis);
Range range = axis.getRange();
- aymin = range.getLowerBound();
- aymax = range.getUpperBound();
- if (ymin != null) aymin = ymin;
- if (ymax != null) aymax = ymax;
- axis.setRange(aymin, aymax);
+ aymin1 = range.getLowerBound();
+ aymax1 = range.getUpperBound();
+ if (ymin1 != null) aymin1 = ymin1;
+ if (ymax1 != null) aymax1 = ymax1;
+ axis.setRange(aymin1, aymax1);
}
- // Right Y axis
+ // Right Y axis setup
Font font = plot.getRangeAxis().getLabelFont();
final NumberAxis rightAxis = new NumberAxis(ylabel2);
rightAxis.setLabelFont(font);
plot.setRangeAxis(1, rightAxis);
+
+ // Right Y axis
+ if (ymin2 != null || ymax2 != null)
+ {
+ Range range = rightAxis.getRange();
+ aymin2 = range.getLowerBound();
+ aymax2 = range.getUpperBound();
+ if (ymin2 != null) aymin2 = ymin2;
+ if (ymax2 != null) aymax2 = ymax2;
+ rightAxis.setRange(aymin2, aymax2);
+ }
+
+ plot.mapDatasetToRangeAxis(0, 0);
+ plot.mapDatasetToRangeAxis(1, 1);
+ plot.configureRangeAxes();
}
/**
@@ -240,12 +266,45 @@
Util.verbose("array:\n" + toString(array));
}
- XYSeriesCollection collection = Util.collection(data, labels,
- names);
+ XYSeriesCollection[] collections =
+ collections(data, labels, names);
- plot(collection, title, xlabel, ylabel1, ylabel2, output);
+ plot(collections, title, xlabel, ylabel1, ylabel2, output);
}
+ static XYSeriesCollection[] collections(List<double[][]> data,
+ List<String> labels,
+ List<String> names)
+ {
+ final XYSeriesCollection[] result = new XYSeriesCollection[2];
+ result[0] = new XYSeriesCollection();
+ result[1] = new XYSeriesCollection();
+
+ int count = 0;
+ for (int i = 0; i < 2; i++)
+ {
+ double[][] d = data.get(i);
+ String label = "data: " + count;
+ try
+ {
+ label = labels.get(count);
+ }
+ catch (IndexOutOfBoundsException e)
+ {}
+
+ XYSeries series = new XYSeries(label);
+ for (int j = 0; j < d.length; j++)
+ {
+ series.add(d[j][0], d[j][1]);
+ }
+
+ series.setDescription(names.get(count));
+ result[i].addSeries(series);
+ count++;
+ }
+ return result;
+ }
+
static void load(String propFile)
{
try
@@ -282,7 +341,8 @@
label.file.data = legend text
width (output image width)
height (output image height)
- xmin, xmax, ymin, ymax (auto-selected if not given)
+ xmin, xmax, ymin1, ymax1, ymin2, ymax2
+ (auto-selected if not given)
bw (Black and white, true/false, default false)
*/
static void scanProperties()
@@ -300,12 +360,19 @@
tmp = properties.getProperty("xmax");
if (tmp != null)
xmax = Double.parseDouble(tmp);
- tmp = properties.getProperty("ymin");
+ tmp = properties.getProperty("ymin1");
if (tmp != null)
- ymin = Double.parseDouble(tmp);
- tmp = properties.getProperty("ymax");
+ ymin1 = Double.parseDouble(tmp);
+ tmp = properties.getProperty("ymax1");
if (tmp != null)
- ymax = Double.parseDouble(tmp);
+ ymax1 = Double.parseDouble(tmp);
+ tmp = properties.getProperty("ymin2");
+ if (tmp != null)
+ ymin2 = Double.parseDouble(tmp);
+ tmp = properties.getProperty("ymax2");
+ if (tmp != null)
+ ymax2 = Double.parseDouble(tmp);
+
tmp = properties.getProperty("bw");
if (tmp != null)
bw = Boolean.parseBoolean(tmp);
More information about the Swift-commit
mailing list