1

I'm trying to change the color of the points on my 3D Scatter Plot. The points change to black, not the color I want and the point on the key changes to the correct color. Does anyone know why this occurs?

import com.panayotis.gnuplot.JavaPlot;
import com.panayotis.gnuplot.plot.*;
import com.panayotis.gnuplot.style.NamedPlotColor;
import com.panayotis.gnuplot.style.PlotStyle;
import com.panayotis.gnuplot.style.Style;


public class ScatterPlot4D {

public static void main(String[] args) {

    int rows = 100;
    int D = 4;

    double [][] dataSet = new double [rows][D];
    for(int x = 0;x < rows; x++){
        for(int y = 0;y < D; y++){
            dataSet[x][y]=Math.random();
        }
    }

    JavaPlot p = new JavaPlot("C:\\Program Files\\gnuplot\\bin\\pgnuplot.exe");       
    p.newGraph3D();

    PlotStyle myStyle = new PlotStyle();
    myStyle.setStyle(Style.POINTS);
    myStyle.setLineType(NamedPlotColor.BLUE); 

    DataSetPlot myPlot = new DataSetPlot(dataSet);  
    myPlot.setPlotStyle(myStyle);

    p.addPlot(myPlot);

    p.splot();

}
}

What's weird is this works when graphing a function.

import com.panayotis.gnuplot.GNUPlot;
import com.panayotis.gnuplot.plot.*;
import com.panayotis.gnuplot.style.NamedPlotColor;
import com.panayotis.gnuplot.style.PlotStyle;
import com.panayotis.gnuplot.style.Style;

public class test3D {

public static void main(String[] args) {

    GNUPlot p = new GNUPlot("C:\\Program Files\\gnuplot\\bin\\pgnuplot.exe");

    p.newGraph3D();

    PlotStyle myStyle = new PlotStyle();
    myStyle.setStyle(Style.IMPULSES);
    myStyle.setLineType(NamedPlotColor.BLUE); 

    FunctionPlot myPlot = new FunctionPlot("tan(x)");
    myPlot.setTitle("3D Plot");
    myPlot.setPlotStyle(myStyle);

    p.addPlot(myPlot);

    p.splot();

}

}

gnuplot is being sent the commands:

gnuplot> set multiplot layout 1,2 rowsfirst downwards
multiplot> _gnuplot_error = 1
multiplot> splot '-' title 'Datafile 1' with points linetype rgb 'blue' ;_gnuplot_error = 0X
input data ('e' ends) > random data is here, not included for brevity
multiplot> if (_gnuplot_error == 1) print '_ERROR_'
 multiplot> unset multiplot
Daniel
  • 2,435
  • 5
  • 26
  • 40
  • Is there any way to dump the GNUPlot stuff to a file so we can see what gnuplot is working with? – mgilson Jul 10 '12 at 02:39
  • @mgilson, yup I included it in the edit – Daniel Jul 10 '12 at 13:23
  • Does the PlotStyle class provide a "setLineColor" method? Essentially, the problem is that your generating `... with points linetype rgb 'blue'` instead of `... with points linecolor rgb 'blue'` – mgilson Jul 10 '12 at 14:04
  • 1
    You could also try `myStyle.setLineType(3);` as linetype 3 in gnuplot defaults to blue. Also, it is worth mentioning that I think you've probably found a bug in javaplot from what I understand in reading the documentation. (Of course, I don't code in java, so I could be wrong). – mgilson Jul 10 '12 at 14:09
  • @mgilson, whoo! that worked! stick your second comment as an answer and I'll mark it. Anyway, I tried changing the source so it would command 'linecolor'; still didn't work. I don't think JavaPlot ever was finished. I had to add the splot command myself – Daniel Jul 10 '12 at 15:09

2 Answers2

0

well, I think that what you need is to use setPointType instead of setLineType in the scatter graph, as is has no Lines. it has only Points.

Miguel
  • 566
  • 1
  • 5
  • 16
  • setPointType takes an int as an argument. Trying various options I've only been able to change the shape of the point, not the color. http://sparky.rice.edu/gnuplot.html makes me think I can change colors with an int but I can't seem to get it to work. – Daniel Jul 10 '12 at 13:48
0

As mgilson said in the comments:

 use myStyle.setLineType(3);

(@mgilson, if you want credit for the answer, just write it yourself, message me and I'll accept it instead_

Daniel
  • 2,435
  • 5
  • 26
  • 40