[Swift-commit] r4186 - in usertools/plotter: . samples/dual src/plotter

noreply at svn.ci.uchicago.edu noreply at svn.ci.uchicago.edu
Mon Mar 14 22:57:11 CDT 2011


Author: wozniak
Date: 2011-03-14 22:57:11 -0500 (Mon, 14 Mar 2011)
New Revision: 4186

Added:
   usertools/plotter/dual.zsh
Modified:
   usertools/plotter/samples/dual/About.txt
   usertools/plotter/samples/dual/plot.cfg
   usertools/plotter/src/plotter/Dual.java
Log:
Setup right-hand Y axis label


Added: usertools/plotter/dual.zsh
===================================================================
--- usertools/plotter/dual.zsh	                        (rev 0)
+++ usertools/plotter/dual.zsh	2011-03-15 03:57:11 UTC (rev 4186)
@@ -0,0 +1,16 @@
+#!/bin/zsh
+
+# DUAL.ZSH
+
+# Create plot with two data sets, two Y axes
+# Arguments passed directly to Dual.java - see there for details
+# usage: dual.zsh <properties> <output file> <data file>*
+
+PLOTTERS=$( cd $( dirname $0 ) ; /bin/pwd )
+
+# declare -p PLOTTERS
+
+source ${PLOTTERS}/classpath.zsh
+[[ $? != 0 ]] && print "Could not build CLASSPATH!" && return 1
+
+java -ea -cp ${CP} plotter.Dual ${*}


Property changes on: usertools/plotter/dual.zsh
___________________________________________________________________
Name: svn:executable
   + *

Modified: usertools/plotter/samples/dual/About.txt
===================================================================
--- usertools/plotter/samples/dual/About.txt	2011-03-15 03:46:04 UTC (rev 4185)
+++ usertools/plotter/samples/dual/About.txt	2011-03-15 03:57:11 UTC (rev 4186)
@@ -1,5 +1,5 @@
 
 To run:
 
-../../lines.zsh plot.cfg tmp.eps set*.data
+../../dual.zsh plot.cfg tmp.eps set*.data
 

Modified: usertools/plotter/samples/dual/plot.cfg
===================================================================
--- usertools/plotter/samples/dual/plot.cfg	2011-03-15 03:46:04 UTC (rev 4185)
+++ usertools/plotter/samples/dual/plot.cfg	2011-03-15 03:57:11 UTC (rev 4186)
@@ -1,7 +1,8 @@
 title = Sample
 
 xlabel = Input
-ylabel = Output
+ylabel1 = Output
+ylabel2 = Secondary
 
 label.set1.data = Set 1
 label.set2.data = Set 2

Modified: usertools/plotter/src/plotter/Dual.java
===================================================================
--- usertools/plotter/src/plotter/Dual.java	2011-03-15 03:46:04 UTC (rev 4185)
+++ usertools/plotter/src/plotter/Dual.java	2011-03-15 03:57:11 UTC (rev 4186)
@@ -3,6 +3,7 @@
 import gnu.getopt.Getopt;
 
 import java.awt.Color;
+import java.awt.Font;
 import java.awt.geom.Rectangle2D;
 import java.io.*;
 import java.util.*;
@@ -84,7 +85,7 @@
       (title, xlabel, ylabel1, collection,
        PlotOrientation.VERTICAL, withLegend, false, false);
 
-    setupPlot(chart, collection);
+    setupPlot(chart, collection, ylabel2);
     chart.draw(g2d, rectangle);
 
     try
@@ -103,7 +104,8 @@
   }
 
   private static void setupPlot(JFreeChart chart,
-                                XYSeriesCollection collection)
+                                XYSeriesCollection collection,
+                                String ylabel2)
   {
     XYPlot plot = chart.getXYPlot();
     XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
@@ -121,19 +123,20 @@
       renderer.setSeriesShapesVisible(1, false);
 
     Plots.setupLegend(chart, properties);
-    setAxes(plot);
+    setAxes(plot, ylabel2);
     plot.setRenderer(renderer);
     plot.setBackgroundPaint(Color.WHITE);
   }
 
-  static void setAxes(XYPlot plot)
+  static void setAxes(XYPlot plot, String ylabel2)
   {
     // Actual values: modify if necessary
     double axmin, axmax, aymin, aymax;
 
     if (xmin != null || xmax != null)
     {
-      NumberAxis axis = (NumberAxis) plot.getDomainAxis();
+      NumberAxis axis = new NumberAxis();
+      plot.setDomainAxis(axis);
       Range range = axis.getRange();
       axmin = range.getLowerBound();
       axmax = range.getUpperBound();
@@ -142,9 +145,11 @@
       axis.setRange(axmin, axmax);
     }
 
+    // Left Y axis
     if (ymin != null || ymax != null)
     {
-      NumberAxis axis = (NumberAxis) plot.getRangeAxis();
+      NumberAxis axis = new NumberAxis();
+      plot.setRangeAxis(0, axis);
       Range range = axis.getRange();
       aymin = range.getLowerBound();
       aymax = range.getUpperBound();
@@ -152,6 +157,12 @@
       if (ymax != null) aymax = ymax;
       axis.setRange(aymin, aymax);
     }
+
+    // Right Y axis
+    Font font = plot.getRangeAxis().getLabelFont();
+    final NumberAxis rightAxis = new NumberAxis(ylabel2);
+    rightAxis.setLabelFont(font);
+    plot.setRangeAxis(1, rightAxis);
   }
 
   /**
@@ -195,7 +206,8 @@
 
     String title = null;
     String xlabel = null;
-    String ylabel = null;
+    String ylabel1 = null;
+    String ylabel2 = null;
     List<double[][]> data = new ArrayList<double[][]>();
     List<String> labels = new ArrayList<String>();
 
@@ -203,7 +215,8 @@
     load(propFile);
     title = properties.getProperty("title");
     xlabel = properties.getProperty("xlabel");
-    ylabel = properties.getProperty("ylabel");
+    ylabel1 = properties.getProperty("ylabel1");
+    ylabel2 = properties.getProperty("ylabel2");
 
     scanProperties();
 
@@ -230,7 +243,7 @@
     XYSeriesCollection collection = Util.collection(data, labels,
                                                     names);
 
-    plot(collection, title, xlabel, ylabel, null, output);
+    plot(collection, title, xlabel, ylabel1, ylabel2, output);
   }
 
   static void load(String propFile)




More information about the Swift-commit mailing list