[Swift-commit] r4965 - usertools/plotter/src/plotter

wozniak at ci.uchicago.edu wozniak at ci.uchicago.edu
Mon Aug 8 17:04:52 CDT 2011


Author: wozniak
Date: 2011-08-08 17:04:52 -0500 (Mon, 08 Aug 2011)
New Revision: 4965

Modified:
   usertools/plotter/src/plotter/Lines.java
Log:
Enable logarithmic axes


Modified: usertools/plotter/src/plotter/Lines.java
===================================================================
--- usertools/plotter/src/plotter/Lines.java	2011-08-08 16:33:46 UTC (rev 4964)
+++ usertools/plotter/src/plotter/Lines.java	2011-08-08 22:04:52 UTC (rev 4965)
@@ -12,6 +12,7 @@
 import org.apache.xmlgraphics.java2d.GraphicContext;
 import org.jfree.chart.ChartFactory;
 import org.jfree.chart.JFreeChart;
+import org.jfree.chart.axis.LogarithmicAxis;
 import org.jfree.chart.axis.NumberAxis;
 import org.jfree.chart.plot.PlotOrientation;
 import org.jfree.chart.plot.XYPlot;
@@ -28,9 +29,16 @@
 {
     static Properties properties;
 
-    // defualt this is not a Black and White plot
+    static String title = null;
+    static String xlabel = "x";
+    static String ylabel = "y";
+    
+    /** If true, use only black and white */ 
     public static boolean bw = false;
 
+    static String axis_x_type = "normal"; 
+    static String axis_y_type = "normal";
+    
     static int width = 400;
     static int height = 400;
 
@@ -74,9 +82,6 @@
         for (int i = 2; i < args.length; i++)
             names.add(args[i]);
 
-        String title = null;
-        String xlabel = null;
-        String ylabel = null;
         List<double[][]> data = new ArrayList<double[][]>();
         List<String> labels = new ArrayList<String>();
 
@@ -165,8 +170,6 @@
             (title, xlabel, ylabel, collection,
              PlotOrientation.VERTICAL, withLegend, false, false);
 
-
-
         setupPlot(chart, collection);
         chart.draw(g2d, rectangle);
 
@@ -207,7 +210,7 @@
             catch (IndexOutOfBoundsException e)
             {}
 
-            Util.verbose( "label: "+label );
+            Util.verbose("label: "+label);
             XYSeries series = new XYSeries(label);
             for (int i = 0; i < d.length; i++)
                 series.add(d[i][0], d[i][1]);
@@ -242,6 +245,8 @@
 
     static void setAxes(XYPlot plot)
     {
+        setAxisTypes(plot);
+        
         // Actual values: modify if necessary
         double axmin, axmax, aymin, aymax;
         if (xmin != null || xmax != null)
@@ -268,6 +273,27 @@
     }
 
 
+    private static void setAxisTypes(XYPlot plot)
+    {
+        if (axis_x_type.equals("logarithmic"))
+        {
+            NumberAxis domainAxis = new LogarithmicAxis(xlabel);
+            plot.setDomainAxis(domainAxis);
+        }
+        else if (!axis_x_type.equals("normal"))
+            throw new RuntimeException
+            ("Invalid axis.x type: " + axis_x_type);
+        
+        if (axis_y_type.equals("logarithmic"))
+        {
+            NumberAxis rangeAxis = new LogarithmicAxis(ylabel);
+            plot.setRangeAxis(rangeAxis);
+        }
+        else if (!axis_y_type.equals("normal"))
+            throw new RuntimeException
+            ("Invalid axis.y type: " + axis_y_type);
+    }
+
     /**
        Various plot properties.  All are currently optional
 
@@ -314,6 +340,12 @@
         tmp = properties.getProperty("legend.enabled");
         if (tmp != null)
             withLegend = Boolean.parseBoolean(tmp);
+        tmp = properties.getProperty("axis.x");
+        if (tmp != null)
+            axis_x_type = tmp;
+        tmp = properties.getProperty("axis.y");
+        if (tmp != null)
+            axis_y_type = tmp;
     }
 
     static void load(String propFile)




More information about the Swift-commit mailing list